Class AbstractWell
- All Implemented Interfaces:
Serializable
,RandomGenerator
- Direct Known Subclasses:
Well1024a
,Well19937a
,Well19937c
,Well44497a
,Well44497b
,Well512a
This generator is described in a paper by François Panneton, Pierre L'Ecuyer and Makoto Matsumoto Improved Long-Period Generators Based on Linear Recurrences Modulo 2 ACM Transactions on Mathematical Software, 32, 1 (2006). The errata for the paper are in wellrng-errata.txt.
- Since:
- 2.2
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final int[]
Index indirection table giving for each index the value index + m1 taking table size into account.protected final int[]
Index indirection table giving for each index the value index + m2 taking table size into account.protected final int[]
Index indirection table giving for each index the value index + m3 taking table size into account.protected int
Current index in the bytes pool.protected final int[]
Index indirection table giving for each index its predecessor taking table size into account.protected final int[]
Index indirection table giving for each index its second predecessor taking table size into account.protected final int[]
Bytes pool. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractWell
(int k, int m1, int m2, int m3) Creates a new random number generator.protected
AbstractWell
(int k, int m1, int m2, int m3, int seed) Creates a new random number generator using a single int seed.protected
AbstractWell
(int k, int m1, int m2, int m3, int[] seed) Creates a new random number generator using an int array seed.protected
AbstractWell
(int k, int m1, int m2, int m3, long seed) Creates a new random number generator using a single long seed. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract int
next
(int bits) Generate next pseudorandom number.void
setSeed
(int seed) Reinitialize the generator as if just built with the given int seed.void
setSeed
(int[] seed) Reinitialize the generator as if just built with the given int array seed.void
setSeed
(long seed) Reinitialize the generator as if just built with the given long seed.Methods inherited from class org.apache.commons.math3.random.BitsStreamGenerator
clear, nextBoolean, nextBytes, nextBytes, nextDouble, nextFloat, nextGaussian, nextInt, nextInt, nextLong, nextLong
-
Field Details
-
index
protected int indexCurrent index in the bytes pool. -
v
protected final int[] vBytes pool. -
iRm1
protected final int[] iRm1Index indirection table giving for each index its predecessor taking table size into account. -
iRm2
protected final int[] iRm2Index indirection table giving for each index its second predecessor taking table size into account. -
i1
protected final int[] i1Index indirection table giving for each index the value index + m1 taking table size into account. -
i2
protected final int[] i2Index indirection table giving for each index the value index + m2 taking table size into account. -
i3
protected final int[] i3Index indirection table giving for each index the value index + m3 taking table size into account.
-
-
Constructor Details
-
AbstractWell
protected AbstractWell(int k, int m1, int m2, int m3) Creates a new random number generator.The instance is initialized using the current time plus the system identity hash code of this instance as the seed.
- Parameters:
k
- number of bits in the pool (not necessarily a multiple of 32)m1
- first parameter of the algorithmm2
- second parameter of the algorithmm3
- third parameter of the algorithm
-
AbstractWell
protected AbstractWell(int k, int m1, int m2, int m3, int seed) Creates a new random number generator using a single int seed.- Parameters:
k
- number of bits in the pool (not necessarily a multiple of 32)m1
- first parameter of the algorithmm2
- second parameter of the algorithmm3
- third parameter of the algorithmseed
- the initial seed (32 bits integer)
-
AbstractWell
protected AbstractWell(int k, int m1, int m2, int m3, int[] seed) Creates a new random number generator using an int array seed.- Parameters:
k
- number of bits in the pool (not necessarily a multiple of 32)m1
- first parameter of the algorithmm2
- second parameter of the algorithmm3
- third parameter of the algorithmseed
- the initial seed (32 bits integers array), if null the seed of the generator will be related to the current time
-
AbstractWell
protected AbstractWell(int k, int m1, int m2, int m3, long seed) Creates a new random number generator using a single long seed.- Parameters:
k
- number of bits in the pool (not necessarily a multiple of 32)m1
- first parameter of the algorithmm2
- second parameter of the algorithmm3
- third parameter of the algorithmseed
- the initial seed (64 bits integer)
-
-
Method Details
-
setSeed
public void setSeed(int seed) Reinitialize the generator as if just built with the given int seed.The state of the generator is exactly the same as a new generator built with the same seed.
- Specified by:
setSeed
in interfaceRandomGenerator
- Specified by:
setSeed
in classBitsStreamGenerator
- Parameters:
seed
- the initial seed (32 bits integer)
-
setSeed
public void setSeed(int[] seed) Reinitialize the generator as if just built with the given int array seed.The state of the generator is exactly the same as a new generator built with the same seed.
- Specified by:
setSeed
in interfaceRandomGenerator
- Specified by:
setSeed
in classBitsStreamGenerator
- Parameters:
seed
- the initial seed (32 bits integers array). If null the seed of the generator will be the system time plus the system identity hash code of the instance.
-
setSeed
public void setSeed(long seed) Reinitialize the generator as if just built with the given long seed.The state of the generator is exactly the same as a new generator built with the same seed.
- Specified by:
setSeed
in interfaceRandomGenerator
- Specified by:
setSeed
in classBitsStreamGenerator
- Parameters:
seed
- the initial seed (64 bits integer)
-
next
protected abstract int next(int bits) Generate next pseudorandom number.This method is the core generation algorithm. It is used by all the public generation methods for the various primitive types
BitsStreamGenerator.nextBoolean()
,BitsStreamGenerator.nextBytes(byte[])
,BitsStreamGenerator.nextDouble()
,BitsStreamGenerator.nextFloat()
,BitsStreamGenerator.nextGaussian()
,BitsStreamGenerator.nextInt()
,BitsStreamGenerator.next(int)
andBitsStreamGenerator.nextLong()
.- Specified by:
next
in classBitsStreamGenerator
- Parameters:
bits
- number of random bits to produce- Returns:
- random bits generated
-