public class DistinctRNG extends java.lang.Object implements StatefulRandomness, SkippingRandomness, java.io.Serializable
long state; calling nextLong() will produce every long exactly
once before repeating. This has been backported from jdkgdxds, which got this from SquidSquad originally. It is
extremely similar to LightRNG, but uses a different mixing/unary-hash function -- where LightRNG uses a
variant on MurmurHash3's mixer called Variant 13, this uses Pelle Evensen's
Moremur mixer,
which performs at the same (high) speed but has somewhat higher quality. This generator has a period of exactly 2 to
the 64. It is a rather fast generator, particularly on Java 8 and/or OpenJ9. It has passed 64TB of PractRand testing
with no anomalies. This is also a SkippingRandomness.
| Modifier and Type | Field and Description |
|---|---|
long |
state
Can be any long value.
|
| Constructor and Description |
|---|
DistinctRNG()
Creates a new generator seeded using Math.random.
|
DistinctRNG(long seed) |
| Modifier and Type | Method and Description |
|---|---|
DistinctRNG |
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 |
getState()
Get the current internal state of the StatefulRandomness 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 |
setSeed(long seed)
This initializes the 1 state of the generator to random values based on the given seed.
|
void |
setState(long state)
Set the current internal state of this StatefulRandomness with a long.
|
long |
skip(long advance)
Advances or rolls back the SkippingRandomness' state without actually generating each number.
|
java.lang.String |
toString() |
public DistinctRNG()
public DistinctRNG(long seed)
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 getState()
StatefulRandomnessgetState in interface StatefulRandomnesspublic void setState(long state)
StatefulRandomnesssetState in interface StatefulRandomnessstate - a 64-bit long. You should avoid passing 0, even though some implementations can handle that.public int next(int bits)
next in interface RandomnessSourcebits - 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 RandomnessSourcepublic long skip(long advance)
SkippingRandomnessRandomnessSource.nextLong(),
and returns the random number produced at that step. Negative numbers can be used to step backward, or 0 can be
given to get the most-recently-generated long from RandomnessSource.nextLong().skip in interface SkippingRandomnessadvance - Number of future generations to skip over; can be negative to backtrack, 0 gets the most-recently-generated numberadvance numberspublic DistinctRNG copy()
copy in interface RandomnessSourcecopy in interface StatefulRandomnesspublic java.lang.String toString()
toString in class java.lang.Objectpublic boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.ObjectCopyright © Eben Howard 2012–2022. All rights reserved.