Package org.uncommons.maths.random
Class JavaRNG
java.lang.Object
java.util.Random
org.uncommons.maths.random.JavaRNG
- All Implemented Interfaces:
Serializable
,RandomGenerator
,RepeatableRNG
This is the default JDK RNG
extended
to implement the RepeatableRNG
interface (for consistency with
the other RNGs in this package).
The MersenneTwisterRNG
should be used in preference to this
class because it is statistically more random and performs slightly
better.
NOTE: Instances of this class do not use the seeding mechanism inherited
from Random
. Calls to the Random.setSeed(long)
method will have no
effect. Instead the seed must be set by a constructor.
- 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
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final byte[]
private static final int
-
Constructor Summary
ConstructorsConstructorDescriptionJavaRNG()
Creates a new RNG and seeds it using the default seeding strategy.JavaRNG
(byte[] seed) Creates an RNG and seeds it with the specified seed data.JavaRNG
(SeedGenerator seedGenerator) Seed the RNG using the provided seed generation strategy. -
Method Summary
Modifier and TypeMethodDescriptionprivate static long
createLongSeed
(byte[] seed) Helper method to convert seed bytes into the long value required by the super class.byte[]
getSeed()
Methods inherited from class java.util.Random
doubles, doubles, doubles, doubles, from, ints, ints, ints, ints, longs, longs, longs, longs, next, nextBoolean, nextBytes, nextDouble, nextFloat, nextGaussian, nextInt, nextInt, nextLong, setSeed
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
-
Field Details
-
SEED_SIZE_BYTES
private static final int SEED_SIZE_BYTES- See Also:
-
seed
private final byte[] seed
-
-
Constructor Details
-
JavaRNG
public JavaRNG()Creates a new RNG and seeds it using the default seeding strategy. -
JavaRNG
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.
-
JavaRNG
public JavaRNG(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
-
createLongSeed
private static long createLongSeed(byte[] seed) Helper method to convert seed bytes into the long value required by the super class. -
getSeed
public byte[] getSeed()- Specified by:
getSeed
in interfaceRepeatableRNG
- Returns:
- The seed data used to initialise this pseudo-random number generator.
-