public class Oriole32RNG extends java.lang.Object implements RandomnessSource, java.io.Serializable
Lathe32RNG
for the fastest generator on GWT I have found that also passes the full 32TB
battery of PractRand's statistical tests. Starfish32RNG has 2D equidistribution while this only has 1D; this means
Starfish32RNG (and GWTRNG) can produce all pairs of ints or all longs (except for one) with equal likelihood, while
Oriole32RNG (and Lathe32RNG) produce some pairs more often than others. In statistical testing, xoroshiro always
fails some binary matrix rank tests, but smaller-state versions fail other tests as well. The changes Oriole makes
apply only to the output of xoroshiro, not its well-tested state transition for the "xoroshiro state" part of this
generator, and these changes eliminate all statistical failures on 32TB of tested data, avoiding the failures the
small-state variant of xoroshiro suffers on BinaryRank, BCFN, DC6, and FPF. It avoids multiplication, like xoroshiro
and much of the xorshift family of generators, and any arithmetic it performs is safe for GWT. Oriole takes advantage
of xoroshiro's flaws being mostly confined to its output's lower bits by rotating the output of xoroshiro (the weaker
32-bit-state version) and adding a "Weyl sequence," essentially a large-increment counter that overflows and wraps
frequently, to the output. Although the upper bits of xoroshiro are not free of artifacts either, they are harder to
find issues with (see
this article by PCG-Random's author for
more detail). It is unclear if the changes made here would improve the larger-state version, but they probably would
help to some extent with at least the binary rank failures. The period is also improved by incorporating the Weyl
sequence, up to 0xFFFFFFFFFFFFFFFF00000000 .
Constructor and Description |
---|
Oriole32RNG()
Creates a new generator seeded using three calls to Math.random().
|
Oriole32RNG(int seed)
Constructs this Oriole32RNG by dispersing the bits of seed using
setSeed(int) across the two parts of state
this has. |
Oriole32RNG(int stateA,
int stateB)
Constructs this Oriole32RNG by calling
setState(int, int, int) on stateA and stateB as given but
producing stateC via stateA ^ stateB ; see that method for the specific details (stateA and stateB are
kept as-is unless they are both 0). |
Oriole32RNG(int stateA,
int stateB,
int stateC)
Constructs this Oriole32RNG by calling
setState(int, int, int) on the arguments as given; see that
method for the specific details (stateA and stateB are kept as-is unless they are both 0). |
Modifier and Type | Method and Description |
---|---|
Oriole32RNG |
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) |
int |
getStateA() |
int |
getStateB() |
int |
getStateC() |
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.
|
int |
nextInt()
Can return any int, positive or negative, of any size permissible in a 32-bit signed integer.
|
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(int seed)
Sets the state of this generator using one int, running it through Zog32RNG's algorithm three times to get
three ints.
|
void |
setState(int stateA,
int stateB,
int stateC)
Sets the current internal state of this Oriole32RNG with three ints, where stateA and stateB can each be any int
unless they are both 0, and stateC can be any int without restrictions.
|
void |
setStateA(int stateA) |
void |
setStateB(int stateB) |
void |
setStateC(int stateC) |
java.lang.String |
toString() |
public Oriole32RNG()
public Oriole32RNG(int seed)
setSeed(int)
across the two parts of state
this has.seed
- a long that won't be used exactly, but will affect both components of statepublic Oriole32RNG(int stateA, int stateB)
setState(int, int, int)
on stateA and stateB as given but
producing stateC via stateA ^ stateB
; see that method for the specific details (stateA and stateB are
kept as-is unless they are both 0).stateA
- the number to use as the first part of the state; this will be 1 instead if both seeds are 0stateB
- the number to use as the second part of the statepublic Oriole32RNG(int stateA, int stateB, int stateC)
setState(int, int, int)
on the arguments as given; see that
method for the specific details (stateA and stateB are kept as-is unless they are both 0).stateA
- the number to use as the first part of the state; this will be 1 instead if both seeds are 0stateB
- the number to use as the second part of the statestateC
- the number to use as the counter part of the state (third part)public int next(int bits)
RandomnessSource
next
in interface RandomnessSource
bits
- the number of bits to be returnedpublic int nextInt()
public long nextLong()
RandomnessSource
nextLong
in interface RandomnessSource
public Oriole32RNG copy()
copy
in interface RandomnessSource
public void setSeed(int seed)
seed
- the int to use to assign this generator's statepublic int getStateA()
public void setStateA(int stateA)
public int getStateB()
public void setStateB(int stateB)
public int getStateC()
public void setStateC(int stateC)
public void setState(int stateA, int stateB, int stateC)
stateA
- any int except 0 (0 will be treated as 1 instead)stateB
- any intpublic 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.