public class WhiskerRNG extends java.lang.Object implements RandomnessSource, java.io.Serializable
long
states performs very few operations per random number, and can often
perform those operations as instruction-parallel. This has been backported from juniper, which is related to jdkgdxds
and SquidSquad. This generator has an unknown period that is statistically extremely likely to be very long (more
than 2 to the 64), and no combinations of states are known that put it in a bad starting state or one with a shorter
period. It is an extremely fast generator on Java 16 and newer, and is probably the fastest generator here when
running on HotSpot Java 16 (10% to 20% faster than the very-similar FourWheelRNG
, the previous fastest
generator). It has passed 64TB of PractRand testing with no anomalies.
Modifier and Type | Field and Description |
---|---|
long |
stateA
Can be any long value.
|
long |
stateB
Can be any long value.
|
long |
stateC
Can be any long value.
|
long |
stateD
Can be any long value.
|
Constructor and Description |
---|
WhiskerRNG()
Creates a new generator seeded using Math.random.
|
WhiskerRNG(long seed) |
WhiskerRNG(long seedA,
long seedB,
long seedC,
long seedD) |
Modifier and Type | Method and Description |
---|---|
WhiskerRNG |
copy()
Produces a copy of this WhiskerRNG that, if next() and/or nextLong() are called on this object and the
copy, both will generate the same sequence of random numbers from the point copy() was called.
|
boolean |
equals(java.lang.Object o) |
long |
getStateA()
Get the "A" part of the internal state as a long.
|
long |
getStateB()
Get the "B" part of the internal state as a long.
|
long |
getStateC()
Get the "C" part of the internal state as a long.
|
long |
getStateD()
Get the "D" part of the internal state as a long.
|
int |
hashCode() |
int |
next(int bits)
Using this method, any algorithm that might use the built-in Java Random
can interface with this randomness source.
|
double |
nextDouble() |
float |
nextFloat() |
int |
nextInt(int bound) |
long |
nextLong()
Using this method, any algorithm that needs to efficiently generate more
than 32 bits of random data can interface with this randomness source.
|
long |
previousLong() |
void |
setSeed(long seed)
This initializes all 4 states of the generator to random values based on the given seed.
|
void |
setStateA(long stateA)
Set the "A" part of the internal state with a long.
|
void |
setStateB(long stateB)
Set the "B" part of the internal state with a long.
|
void |
setStateC(long stateC)
Set the "C" part of the internal state with a long.
|
void |
setStateD(long stateD)
Set the "D" part of the internal state with a long.
|
java.lang.String |
toString() |
public long stateA
public long stateB
public long stateC
public long stateD
public WhiskerRNG()
public WhiskerRNG(long seed)
public WhiskerRNG(long seedA, long seedB, long seedC, long seedD)
public void setSeed(long seed)
seed
- the initial seed; may be any longpublic long getStateA()
public void setStateA(long stateA)
stateA
- any 64-bit longpublic long getStateB()
public void setStateB(long stateB)
stateB
- any 64-bit longpublic long getStateC()
public void setStateC(long stateC)
stateC
- any 64-bit longpublic long getStateD()
public void setStateD(long stateD)
stateD
- any 64-bit longpublic long nextLong()
RandomnessSource
nextLong
in interface RandomnessSource
public long previousLong()
public int next(int bits)
RandomnessSource
next
in interface RandomnessSource
bits
- the number of bits to be returnedpublic double nextDouble()
public float nextFloat()
public int nextInt(int bound)
public WhiskerRNG copy()
copy
in interface RandomnessSource
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
Copyright © Eben Howard 2012–2022. All rights reserved.