public class Tausworthe extends java.lang.Object implements RandomNumber
The next seed is ((current seed) xor (current seed shifted 13 bits to the right) xor (current seed shifted 18 bits to the left)) and 0x7FFFFFFF [31 bits]
Modifier and Type | Field and Description |
---|---|
static long |
BITMASK |
static double |
MULTIPLICATIVE_FACTOR |
private long |
originalSeed
The seed specified by the last setSeed.
|
private long |
seed
The current value of the seed.
|
static int |
SHIFT_LEFT |
static int |
SHIFT_RIGHT |
Constructor and Description |
---|
Tausworthe()
Creates a new instance of Tausworthe with the default seed (42)
|
Modifier and Type | Method and Description |
---|---|
double |
draw()
Generates the next value scaled to be U(0,1)
|
long |
drawLong()
Generates the next value.
|
double |
getMultiplier()
The number to multiply the seed by to scale it to a U(0,1)
|
long |
getSeed()
Returns the current value of the seed.
|
long[] |
getSeeds()
Returns a single element array containing the current value of the seed.
|
void |
resetSeed()
Resets seed to last setSeed() value
|
void |
setSeed(long seed)
Sets the seed to the given value.
|
void |
setSeeds(long[] seed)
Sets the seed to the value of the first element in the array.
|
java.lang.String |
toString()
Returns a String containing the name of this RandomNumber with the current seed.
|
public static final long BITMASK
public static final int SHIFT_RIGHT
public static final int SHIFT_LEFT
public static final double MULTIPLICATIVE_FACTOR
private long seed
private long originalSeed
public Tausworthe()
public long drawLong()
drawLong
in interface RandomNumber
public double draw()
draw
in interface RandomNumber
public long getSeed()
getSeed
in interface RandomNumber
public long[] getSeeds()
getSeeds
in interface RandomNumber
public void resetSeed()
resetSeed
in interface RandomNumber
public void setSeed(long seed)
setSeed
in interface RandomNumber
seed
- The new random number seedpublic void setSeeds(long[] seed)
setSeeds
in interface RandomNumber
seed
- An array with at least one element containing the new seed.java.lang.IllegalArgumentException
- If the array does not have at least one element.public java.lang.String toString()
toString
in class java.lang.Object
public double getMultiplier()
getMultiplier
in interface RandomNumber