Class XORShiftRNG
java.lang.Object
java.util.Random
org.uncommons.maths.random.XORShiftRNG
- All Implemented Interfaces:
Serializable, RandomGenerator, RepeatableRNG
Very fast pseudo random number generator. See
this
page for a description. This RNG has a period of about 2^160, which is not as long
as the MersenneTwisterRNG but it is faster.
NOTE: Because instances of this class require 160-bit seeds, it is not
possible to seed this RNG using the Random.setSeed(long) method inherited
from Random. Calls to this method will have no effect.
Instead the seed must be set by a constructor.
- Since:
- 1.2
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface RandomGenerator
RandomGenerator.ArbitrarilyJumpableGenerator, RandomGenerator.JumpableGenerator, RandomGenerator.LeapableGenerator, RandomGenerator.SplittableGenerator, RandomGenerator.StreamableGenerator -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ReentrantLockprivate final byte[]private static final intprivate intprivate intprivate intprivate intprivate int -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new RNG and seeds it using the default seeding strategy.XORShiftRNG(byte[] seed) Creates an RNG and seeds it with the specified seed data.XORShiftRNG(SeedGenerator seedGenerator) Seed the RNG using the provided seed generation strategy. -
Method Summary
Methods inherited from class Random
doubles, doubles, doubles, doubles, from, ints, ints, ints, ints, longs, longs, longs, longs, nextBoolean, nextBytes, nextDouble, nextFloat, nextGaussian, nextInt, nextInt, nextLong, setSeedMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface RandomGenerator
equiDoubles, isDeprecated, nextDouble, nextDouble, nextExponential, nextFloat, nextFloat, nextGaussian, nextInt, nextLong, nextLong
-
Field Details
-
SEED_SIZE_BYTES
private static final int SEED_SIZE_BYTES- See Also:
-
state1
private int state1 -
state2
private int state2 -
state3
private int state3 -
state4
private int state4 -
state5
private int state5 -
seed
private final byte[] seed -
lock
-
-
Constructor Details
-
XORShiftRNG
public XORShiftRNG()Creates a new RNG and seeds it using the default seeding strategy. -
XORShiftRNG
Seed the RNG using the provided seed generation strategy.- Parameters:
seedGenerator- The seed generation strategy that will provide the seed value for this RNG.- Throws:
SeedException- If there is a problem generating a seed.
-
XORShiftRNG
public XORShiftRNG(byte[] seed) Creates an RNG and seeds it with the specified seed data.- Parameters:
seed- The seed data used to initialise the RNG.
-
-
Method Details
-
getSeed
public byte[] getSeed()- Specified by:
getSeedin interfaceRepeatableRNG- Returns:
- The seed data used to initialise this pseudo-random number generator.
-
next
-