public class FourWheelRNG extends java.lang.Object implements RandomnessSource, java.io.Serializable
long
states that changes its state with complex ways it can connect states to
other states. This has been backported from jdkgdxds, which got this from SquidSquad originally. 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 almost the fastest generator here when running on HotSpot Java 16. The newer,
very-similar WhiskerRNG
is 10% to 20% faster. FourWheelRNG has passed 64TB of PractRand testing with no
anomalies, and 4PB of hwd testing. It does fail one test (Remortality) after hundreds of PB of tested data.
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 |
---|
FourWheelRNG()
Creates a new generator seeded using Math.random.
|
FourWheelRNG(long seed) |
FourWheelRNG(long seedA,
long seedB,
long seedC,
long seedD) |
Modifier and Type | Method and Description |
---|---|
FourWheelRNG |
copy()
Produces a copy of this FourWheelRNG 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.
|
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 FourWheelRNG()
public FourWheelRNG(long seed)
public FourWheelRNG(long seedA, long seedB, long seedC, long seedD)
public void setSeed(long seed)
nextLong()
(because stateD
is guaranteed to be
different for every different 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 FourWheelRNG 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.