Top Description Fields Constructors Methods
org.apache.commons.math3.random

public Class SynchronizedRandomGenerator

extends Object
implements RandomGenerator
Class Inheritance
All Implemented Interfaces
org.apache.commons.math3.random.RandomGenerator

Any RandomGenerator implementation can be thread-safe if it is used through an instance of this class. This is achieved by enclosing calls to the methods of the actual generator inside the overridden synchronized methods of this class.
Since
3.1

Field Summary

Modifier and TypeField and Description
private final RandomGenerator
wrapped

Object to which all calls will be delegated.

Constructor Summary

AccessConstructor and Description
public
SynchronizedRandomGenerator(RandomGenerator
Generator whose methods will be called through their corresponding overridden synchronized version. To ensure thread-safety, the wrapped generator must not be used directly.
rng
)

Creates a synchronized wrapper for the given RandomGenerator instance.

Method Summary

Modifier and TypeMethod and Description
public synchronized boolean
nextBoolean()

Implements org.apache.commons.math3.random.RandomGenerator.nextBoolean.

Returns the next pseudorandom, uniformly distributed boolean value from this random number generator's sequence.

public synchronized void
nextBytes(byte[]
the non-null byte array in which to put the random bytes
bytes
)

Implements org.apache.commons.math3.random.RandomGenerator.nextBytes.

Generates random bytes and places them into a user-supplied byte array.

public synchronized double
nextDouble()

Implements org.apache.commons.math3.random.RandomGenerator.nextDouble.

Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 from this random number generator's sequence.

public synchronized float
nextFloat()

Implements org.apache.commons.math3.random.RandomGenerator.nextFloat.

Returns the next pseudorandom, uniformly distributed float value between 0.0 and 1.0 from this random number generator's sequence.

public synchronized double
nextGaussian()

Implements org.apache.commons.math3.random.RandomGenerator.nextGaussian.

Returns the next pseudorandom, Gaussian ("normally") distributed double value with mean 0.0 and standard deviation 1.0 from this random number generator's sequence.

public synchronized int
nextInt()

Implements org.apache.commons.math3.random.RandomGenerator.nextInt.

Returns the next pseudorandom, uniformly distributed int value from this random number generator's sequence.

public synchronized int
nextInt(int
the bound on the random number to be returned. Must be positive.
n
)

Implements org.apache.commons.math3.random.RandomGenerator.nextInt.

Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.

public synchronized long
nextLong()

Implements org.apache.commons.math3.random.RandomGenerator.nextLong.

Returns the next pseudorandom, uniformly distributed long value from this random number generator's sequence.

public synchronized void
setSeed(int
the seed value
seed
)

Implements org.apache.commons.math3.random.RandomGenerator.setSeed.

Sets the seed of the underlying random number generator using an int seed.

public synchronized void
setSeed(int[]
the seed value
seed
)

Implements org.apache.commons.math3.random.RandomGenerator.setSeed.

Sets the seed of the underlying random number generator using an int array seed.

public synchronized void
setSeed(long
the seed value
seed
)

Implements org.apache.commons.math3.random.RandomGenerator.setSeed.

Sets the seed of the underlying random number generator using a long seed.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

wrappedback to summary
private final RandomGenerator wrapped

Object to which all calls will be delegated.

Constructor Detail

SynchronizedRandomGeneratorback to summary
public SynchronizedRandomGenerator(RandomGenerator rng)

Creates a synchronized wrapper for the given RandomGenerator instance.

Parameters
rng:RandomGenerator

Generator whose methods will be called through their corresponding overridden synchronized version. To ensure thread-safety, the wrapped generator must not be used directly.

Method Detail

nextBooleanback to summary
public synchronized boolean nextBoolean()

Implements org.apache.commons.math3.random.RandomGenerator.nextBoolean.

Doc from org.apache.commons.math3.random.RandomGenerator.nextBoolean.

Returns the next pseudorandom, uniformly distributed boolean value from this random number generator's sequence.

Returns:boolean

the next pseudorandom, uniformly distributed boolean value from this random number generator's sequence

nextBytesback to summary
public synchronized void nextBytes(byte[] bytes)

Implements org.apache.commons.math3.random.RandomGenerator.nextBytes.

Doc from org.apache.commons.math3.random.RandomGenerator.nextBytes.

Generates random bytes and places them into a user-supplied byte array. The number of random bytes produced is equal to the length of the byte array.

Parameters
bytes:byte[]

the non-null byte array in which to put the random bytes

nextDoubleback to summary
public synchronized double nextDouble()

Implements org.apache.commons.math3.random.RandomGenerator.nextDouble.

Doc from org.apache.commons.math3.random.RandomGenerator.nextDouble.

Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 from this random number generator's sequence.

Returns:double

the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 from this random number generator's sequence

nextFloatback to summary
public synchronized float nextFloat()

Implements org.apache.commons.math3.random.RandomGenerator.nextFloat.

Doc from org.apache.commons.math3.random.RandomGenerator.nextFloat.

Returns the next pseudorandom, uniformly distributed float value between 0.0 and 1.0 from this random number generator's sequence.

Returns:float

the next pseudorandom, uniformly distributed float value between 0.0 and 1.0 from this random number generator's sequence

nextGaussianback to summary
public synchronized double nextGaussian()

Implements org.apache.commons.math3.random.RandomGenerator.nextGaussian.

Doc from org.apache.commons.math3.random.RandomGenerator.nextGaussian.

Returns the next pseudorandom, Gaussian ("normally") distributed double value with mean 0.0 and standard deviation 1.0 from this random number generator's sequence.

Returns:double

the next pseudorandom, Gaussian ("normally") distributed double value with mean 0.0 and standard deviation 1.0 from this random number generator's sequence

nextIntback to summary
public synchronized int nextInt()

Implements org.apache.commons.math3.random.RandomGenerator.nextInt.

Doc from org.apache.commons.math3.random.RandomGenerator.nextInt.

Returns the next pseudorandom, uniformly distributed int value from this random number generator's sequence. All 232 possible int values should be produced with (approximately) equal probability.

Returns:int

the next pseudorandom, uniformly distributed int value from this random number generator's sequence

nextIntback to summary
public synchronized int nextInt(int n)

Implements org.apache.commons.math3.random.RandomGenerator.nextInt.

Doc from org.apache.commons.math3.random.RandomGenerator.nextInt.

Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.

Parameters
n:int

the bound on the random number to be returned. Must be positive.

Returns:int

a pseudorandom, uniformly distributed int value between 0 (inclusive) and n (exclusive).

nextLongback to summary
public synchronized long nextLong()

Implements org.apache.commons.math3.random.RandomGenerator.nextLong.

Doc from org.apache.commons.math3.random.RandomGenerator.nextLong.

Returns the next pseudorandom, uniformly distributed long value from this random number generator's sequence. All 264 possible long values should be produced with (approximately) equal probability.

Returns:long

the next pseudorandom, uniformly distributed long value from this random number generator's sequence

setSeedback to summary
public synchronized void setSeed(int seed)

Implements org.apache.commons.math3.random.RandomGenerator.setSeed.

Doc from org.apache.commons.math3.random.RandomGenerator.setSeed.

Sets the seed of the underlying random number generator using an int seed.

Sequences of values generated starting with the same seeds should be identical.

Parameters
seed:int

the seed value

setSeedback to summary
public synchronized void setSeed(int[] seed)

Implements org.apache.commons.math3.random.RandomGenerator.setSeed.

Doc from org.apache.commons.math3.random.RandomGenerator.setSeed.

Sets the seed of the underlying random number generator using an int array seed.

Sequences of values generated starting with the same seeds should be identical.

Parameters
seed:int[]

the seed value

setSeedback to summary
public synchronized void setSeed(long seed)

Implements org.apache.commons.math3.random.RandomGenerator.setSeed.

Doc from org.apache.commons.math3.random.RandomGenerator.setSeed.

Sets the seed of the underlying random number generator using a long seed.

Sequences of values generated starting with the same seeds should be identical.

Parameters
seed:long

the seed value