public class OrbitRNG extends java.lang.Object implements RandomnessSource, java.io.Serializable
ThrustAltRNG
that gives up some speed to gain a much better period and the ability to produce
all possible long values over that period. Its period is 2 to the 128, and it produces all long outputs with equal
likelihood. OrbitRNG is close to ThrustAltRNG in implementation, and ThrustAltRNG passes PractRand and TestU01 just
fine, but OrbitRNG should actually be more robust. For some purposes you may want to instead consider
TangleRNG
, which also has two states and uses a very similar algorithm, but it skips some work Orbit does and
in doing so speeds up a lot and drops its period down to 2 to the 64. An individual TangleRNG can't produce all
possible long outputs and can produce some duplicates, but each pair of states for a TangleRNG has a different set of
which outputs will be skipped and which will be duplicated. Since it would require months of solid number generation
to exhaust the period of a TangleRNG, and that's the only time an output can be confirmed as skipped, it's probably
fine for some usage to use many different TangleRNGs, all seeded differently. In other cases you could use just one
OrbitRNG; its period is large enough not to worry about exhausting it in a game, though it isn't quite as fast as
TangleRNG. Orbit is extremely close in speed to a 64-bit variant on Lathe32RNG
, and should have similarly
high quality; it should be slightly slower than XoRoRNG
but doesn't fail the statistical tests that XoRo
fails rather badly.
TangleRNG
.
Modifier and Type | Field and Description |
---|---|
long |
stateA
Can be any long value.
|
long |
stateB |
Constructor and Description |
---|
OrbitRNG()
Creates a new generator seeded using Math.random.
|
OrbitRNG(long seed) |
OrbitRNG(long seedA,
long seedB) |
Modifier and Type | Method and Description |
---|---|
OrbitRNG |
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.
|
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.
|
java.lang.String |
toString() |
public OrbitRNG()
public OrbitRNG(long seed)
public OrbitRNG(long seedA, long seedB)
public long getStateA()
public void setStateA(long stateA)
stateA
- any 64-bit longpublic long getStateB()
public void setStateB(long stateB)
stateB
- any 64-bit longpublic int next(int bits)
next
in interface RandomnessSource
bits
- the number of bits to be returnedpublic long nextLong()
Get a random long between Long.MIN_VALUE and Long.MAX_VALUE (both inclusive).
nextLong
in interface RandomnessSource
public OrbitRNG 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.