Package org.moeaframework.parallel.util
Class ThreadLocalMersenneTwister
java.lang.Object
java.util.Random
org.moeaframework.parallel.util.ThreadLocalMersenneTwister
- All Implemented Interfaces:
Serializable
,RandomGenerator
A thread-safe version of the
MersenneTwister
random number generator (RNG). Each thread is assigned a
unique instance of the RNG with its own seed. To use:
PRNG.setRandom(ThreadLocalMersenneTwister.getInstance());Note: Java also has the that can provide similar access to random numbers across threads. The Mersenne Twister, however, has better characteristics (extremely long period, high equidistribution, etc.).
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface java.util.random.RandomGenerator
RandomGenerator.ArbitrarilyJumpableGenerator, RandomGenerator.JumpableGenerator, RandomGenerator.LeapableGenerator, RandomGenerator.SplittableGenerator, RandomGenerator.StreamableGenerator
-
Method Summary
Methods inherited from class java.util.Random
doubles, doubles, doubles, doubles, ints, ints, ints, ints, longs, longs, longs, longs, next
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.random.RandomGenerator
isDeprecated, nextDouble, nextDouble, nextExponential, nextFloat, nextFloat, nextGaussian, nextInt, nextLong, nextLong
-
Method Details
-
getInstance
Returns the singleton instance of this synchronized Mersenne Twister RNG.- Returns:
- the singleton instance
-
setSeed
public void setSeed(long seed) -
nextBytes
public void nextBytes(byte[] bytes) - Specified by:
nextBytes
in interfaceRandomGenerator
- Overrides:
nextBytes
in classRandom
-
nextInt
public int nextInt()- Specified by:
nextInt
in interfaceRandomGenerator
- Overrides:
nextInt
in classRandom
-
nextInt
public int nextInt(int n) - Specified by:
nextInt
in interfaceRandomGenerator
- Overrides:
nextInt
in classRandom
-
nextLong
public long nextLong()- Specified by:
nextLong
in interfaceRandomGenerator
- Overrides:
nextLong
in classRandom
-
nextBoolean
public boolean nextBoolean()- Specified by:
nextBoolean
in interfaceRandomGenerator
- Overrides:
nextBoolean
in classRandom
-
nextFloat
public float nextFloat()- Specified by:
nextFloat
in interfaceRandomGenerator
- Overrides:
nextFloat
in classRandom
-
nextDouble
public double nextDouble()- Specified by:
nextDouble
in interfaceRandomGenerator
- Overrides:
nextDouble
in classRandom
-
nextGaussian
public double nextGaussian()- Specified by:
nextGaussian
in interfaceRandomGenerator
- Overrides:
nextGaussian
in classRandom
-