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, nextMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:
nextBytesin interfaceRandomGenerator- Overrides:
nextBytesin classRandom
-
nextInt
public int nextInt()- Specified by:
nextIntin interfaceRandomGenerator- Overrides:
nextIntin classRandom
-
nextInt
public int nextInt(int n) - Specified by:
nextIntin interfaceRandomGenerator- Overrides:
nextIntin classRandom
-
nextLong
public long nextLong()- Specified by:
nextLongin interfaceRandomGenerator- Overrides:
nextLongin classRandom
-
nextBoolean
public boolean nextBoolean()- Specified by:
nextBooleanin interfaceRandomGenerator- Overrides:
nextBooleanin classRandom
-
nextFloat
public float nextFloat()- Specified by:
nextFloatin interfaceRandomGenerator- Overrides:
nextFloatin classRandom
-
nextDouble
public double nextDouble()- Specified by:
nextDoublein interfaceRandomGenerator- Overrides:
nextDoublein classRandom
-
nextGaussian
public double nextGaussian()- Specified by:
nextGaussianin interfaceRandomGenerator- Overrides:
nextGaussianin classRandom
-