Package squidpony.squidmath
Class GoatRNG
java.lang.Object
squidpony.squidmath.GoatRNG
- All Implemented Interfaces:
Serializable
,RandomnessSource
public final class GoatRNG extends Object implements RandomnessSource, Serializable
A larger-period generator with 128 bits of state, good speed, and high quality in PractRand testing; it is at least
1-dimensionally equidistributed. It appears to be slightly faster than a Xorshift128+ generator, like RandomXS128 in
libGDX, with practically the same period (this has a period of 2 to the 128), but it isn't as fast as as
Unlike most RNGs from outside Goat, Gear, and Orbit's family, this relies on a conditional and comparison to achieve both its period and randomness goals. All of these generators use two additive sequences for their states, and stall one of the state updates when the other state matches a criterion. For Orbit, it stalls only when stateA is 0 (roughly 1 in 18 quintillion generated numbers); for Gear, stateA must be less than 1863783533 away from the minimum long value (roughly 1 in 10 billion generated numbers), and here, stateA must be less than 5096992405936522019L to stall (roughly 3 in 4 generated numbers).
Unlike GearRNG, this allows all long values for both states; unlike OrbitRNG, there shouldn't be significant correlation between an even value for stateB and the value 1 greater than that (such as 4 and 5, or 100 and 101).
The name comes from how goats are reliably hard to predict, like an RNG should be. It is called GhoulRNG in some tests run on it; an earlier version of GoatRNG also exists that does well in testing for the first 32TB and then suddenly has serious issues.
Created by Tommy Ettinger on 5/8/2020.
OrbitRNG
or GearRNG
(Goat seems to have higher statistical quality than either of those late in
testing, though). It passes 64TB of PractRand testing with no anomalies, and might be able to endure tests past even
that (the default setting stops at 32TB); I had set up PractRand to test up to 128TB but it ran out of memory after
5 days of nonstop testing on all 6 cores. If 16GB of RAM isn't enough to find even an anomaly in GoatRNG, then it is
probably quite good.
Unlike most RNGs from outside Goat, Gear, and Orbit's family, this relies on a conditional and comparison to achieve both its period and randomness goals. All of these generators use two additive sequences for their states, and stall one of the state updates when the other state matches a criterion. For Orbit, it stalls only when stateA is 0 (roughly 1 in 18 quintillion generated numbers); for Gear, stateA must be less than 1863783533 away from the minimum long value (roughly 1 in 10 billion generated numbers), and here, stateA must be less than 5096992405936522019L to stall (roughly 3 in 4 generated numbers).
Unlike GearRNG, this allows all long values for both states; unlike OrbitRNG, there shouldn't be significant correlation between an even value for stateB and the value 1 greater than that (such as 4 and 5, or 100 and 101).
The name comes from how goats are reliably hard to predict, like an RNG should be. It is called GhoulRNG in some tests run on it; an earlier version of GoatRNG also exists that does well in testing for the first 32TB and then suddenly has serious issues.
Created by Tommy Ettinger on 5/8/2020.
- See Also:
- Serialized Form
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description GoatRNG
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(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.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.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.String
toString()
-
Field Details
-
Constructor Details
-
Method Details
-
getStateA
Get the "A" part of the internal state as a long.- Returns:
- the current internal state of this object.
-
setStateA
Set the "A" part of the internal state with a long.- Parameters:
stateA
- any 64-bit long
-
getStateB
Get the "B" part of the internal state as a long.- Returns:
- the current internal "B" state of this object.
-
setStateB
Set the "B" part of the internal state with a long.- Parameters:
stateB
- any 64-bit long
-
next
Using this method, any algorithm that might use the built-in Java Random can interface with this randomness source.- Specified by:
next
in interfaceRandomnessSource
- Parameters:
bits
- the number of bits to be returned- Returns:
- the integer containing the appropriate number of bits
-
nextLong
Using this method, any algorithm that needs to efficiently generate more than 32 bits of random data can interface with this randomness source.Get a random long between Long.MIN_VALUE and Long.MAX_VALUE (both inclusive).
- Specified by:
nextLong
in interfaceRandomnessSource
- Returns:
- a random long between Long.MIN_VALUE and Long.MAX_VALUE (both inclusive)
-
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. This just need to copy the state so it isn't shared, usually, and produce a new value with the same exact state.- Specified by:
copy
in interfaceRandomnessSource
- Returns:
- a copy of this RandomnessSource
-
toString
-
equals
-
hashCode
-