public class TricycleRNG extends java.lang.Object implements RandomnessSource, java.io.Serializable
long
states that changes its state with three 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 a very fast generator,
particularly on Java 16 and newer. It has passed 64TB of PractRand testing with no anomalies, and 4PB of hwd testing.
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.
|
Constructor and Description |
---|
TricycleRNG()
Creates a new generator seeded using Math.random.
|
TricycleRNG(long seed) |
TricycleRNG(long seedA,
long seedB,
long seedC) |
Modifier and Type | Method and Description |
---|---|
TricycleRNG |
copy()
Produces a copy of this RandomnessSource 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.
|
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 3 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.
|
java.lang.String |
toString() |
public long stateA
public long stateB
public long stateC
public TricycleRNG()
public TricycleRNG(long seed)
public TricycleRNG(long seedA, long seedB, long seedC)
public void setSeed(long seed)
nextLong()
(because stateA
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 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 TricycleRNG 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.