edu.cornell.lassp.houle.RngPack
Class RandomSynchronized

java.lang.Object
  extended byedu.cornell.lassp.houle.RngPack.RandomElement
      extended byedu.cornell.lassp.houle.RngPack.RandomSynchronized
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

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
RandomSynchronized(RandomElement rng)
           
 
Method Summary
 int choose(int lo, int hi)
          Wrapped so generators can override.
 double gaussian()
          Must be synchronized because state is stored in BMoutput
 double raw()
          Synchronized the raw() method, which is generally not threadsafe.
 void raw(double[] d, int n)
          This method probably isn't threadsafe in implementations, so it's synchronized
 
Methods inherited from class edu.cornell.lassp.houle.RngPack.RandomElement
choose, clone, coin, coin, gaussian, powlaw, raw, uniform
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RandomSynchronized

public RandomSynchronized(RandomElement rng)
Method Detail

raw

public double raw()
Synchronized the raw() method, which is generally not threadsafe.

Specified by:
raw in class RandomElement
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:
raw in class RandomElement
Parameters:
d - array to be filled with doubles
n - number of doubles to generate

choose

public int choose(int lo,
                  int hi)
Wrapped so generators can override.

Overrides:
choose in class RandomElement
Parameters:
lo - lower limit of range
hi - 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:
gaussian in class RandomElement
Returns:
a random real with a gaussian distribution, standard deviation