edu.cornell.lassp.houle.RngPack
Class RandomSynchronized
- java.lang.Object
-
- edu.cornell.lassp.houle.RngPack.RandomElement
-
- edu.cornell.lassp.houle.RngPack.RandomSynchronized
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable
public abstract class RandomSynchronized extends RandomElement implements java.io.Serializable
RandomSynchronized is a wrapper class that makes a random number generator safe for multi-threaded operation by serializing access in time. For high-performance applications, it is better for each thread to have it's own random number generator. Note this class is declared serializable, but serialization won't be successful if it's wrapping a non-serializable generator.Source code is available.
- See Also:
RandomElement, Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description RandomSynchronized(RandomElement rng)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description intchoose(int lo, int hi)Wrapped so generators can override.doublegaussian()Must be synchronized because state is stored in BMoutputdoubleraw()Synchronized the raw() method, which is generally not threadsafe.voidraw(double[] d, int n)This method probably isn't threadsafe in implementations, so it's synchronized
-
-
-
Constructor Detail
-
RandomSynchronized
public RandomSynchronized(RandomElement rng)
-
-
Method Detail
-
raw
public double raw()
Synchronized the raw() method, which is generally not threadsafe.- Specified by:
rawin classRandomElement- Returns:
- a random double in the range [0,1]
- See Also:
RandomJava
-
raw
public void raw(double[] d, int n)This method probably isn't threadsafe in implementations, so it's synchronized- Overrides:
rawin classRandomElement- Parameters:
d- array to be filled with doublesn- number of doubles to generate
-
choose
public int choose(int lo, int hi)Wrapped so generators can override.- Overrides:
choosein classRandomElement- Parameters:
lo- lower limit of rangehi- upper limit of range- Returns:
- a random integer in the range lo, lo+1, ... ,hi
-
gaussian
public double gaussian()
Must be synchronized because state is stored in BMoutput- Overrides:
gaussianin classRandomElement- Returns:
- a random real with a gaussian distribution, standard deviation
-
-
DMelt 3.0 © DataMelt by jWork.ORG