public class NSSrng extends java.lang.Object implements RandomNumber
It is an implementation of a combined tausworthe generator as described by L'Ecuyer in his paper titled, 'Maximally Equidistributed Combined Tausworthe Generators.' This uses a fast software implementation which is available when the proper conditions are met. The fast implementation is used to generate random numbers from three Tausworthe generator which are combined through a simple bitwise exclusive-or of the results of each generator. The period of the individual generators are 2^31-1, 2^29-1 and 2^28-1; yielding a period for the combined generator in the order of approximately 2^88. It requires the keeping track of 3 seed values- one for each generator. The seeds, s1, s2, s3, must be initially set to non-zero values greater than 1, 7 and 15. This is explained further in the paper. Also in talking to the author and making observations of the generators, it was found that if all of the starting values are small then the generator requires a few steps to warm up. The individual tausworthe generator will produce numbers between their minimum starting value and (232)-1 inclusive, but the combined generator will produce numbers from zero to the max value (232-1 or 4294967295L) inclusive.
Original C++ implementation by Metron, Incorporated.
Translated to Java by John Ruck, Rolands and Associates Corporation.
Modifier and Type | Field and Description |
---|---|
protected boolean |
debug
If true, prints debug information
|
private static double |
INVERSE
The reciprocal of MAX_VALUE
|
private static long |
M1
mask for first generator = (2^32)-2
|
private static long |
M2
mask for second generator = (2^32)-8
|
private static long |
M3
mask for third generator = (2^32)-16
|
private static long |
MAX_VALUE
Maximum allowed value of the seeds.
|
protected long |
originalSeed
The original value of S1, the generator will be reset using this value
when resetSeed is called.
|
protected long |
S1
One of three seeds.
|
protected long |
S2
One of three seeds.
|
protected long |
S3
One of three seeds.
|
Constructor and Description |
---|
NSSrng()
Constructs a new NSSrng.
|
Modifier and Type | Method and Description |
---|---|
double |
draw()
Draws a random number and returns it as U(0,1)
|
long |
drawLong()
Draws a random number and returns it as an integer.
|
boolean |
getDebug() |
double |
getMultiplier()
Returns the value for this RandomNumber needed to scale
a number produced by drawLong to result in U(0,1).
|
long |
getSeed()
Returns the current value of the current seed.
|
long[] |
getSeeds()
Gets the current (not original) value of the seeds for this RandomNumber.
|
protected void |
initialize_random_generator()
Sets the seed for S2 and S3 based on the value of S1 and "warms up" the
generator.
|
void |
resetSeed()
Resets seed to last setSeed() value
|
void |
setDebug(boolean debug) |
void |
setSeed(long seed)
Sets the seed to the given value.
|
void |
setSeeds(long[] seed)
Sets all 3 seeds of this RandomNumber.
|
java.lang.String |
toString()
Returns a String containing information about NSSrng, including the starting seed.
|
private static final long MAX_VALUE
private static final double INVERSE
private static final long M1
private static final long M2
private static final long M3
protected long S1
protected long S2
protected long S3
protected long originalSeed
protected boolean debug
public NSSrng()
public void setDebug(boolean debug)
debug
- true, if printing debug informationpublic boolean getDebug()
public long drawLong()
RandomNumber
drawLong
in interface RandomNumber
public double draw()
RandomNumber
draw
in interface RandomNumber
protected void initialize_random_generator()
public void setSeed(long seed)
setSeed
in interface RandomNumber
seed
- The new random number seedjava.lang.IllegalArgumentException
- If the seed is not greater than 1public long getSeed()
getSeed
in interface RandomNumber
public void resetSeed()
RandomNumber
resetSeed
in interface RandomNumber
public void setSeeds(long[] seed)
setSeeds
in interface RandomNumber
seed
- An array of 3 longs.java.lang.IllegalArgumentException
- If the array doesn't contain exactly 3 Longs.public long[] getSeeds()
RandomNumber
getSeeds
in interface RandomNumber
public double getMultiplier()
RandomNumber
getMultiplier
in interface RandomNumber
public java.lang.String toString()
toString
in class java.lang.Object