public class Mover32RNG extends java.lang.Object implements RandomnessSource
Starfish32RNG
(which is also high-quality) and is also faster
than Lathe32RNG
(which is very fast but has quality issues). However, this is slower than Lathe32RNG when
using GWT and viewing in Firefox; for some reason Starfish32RNG
optimizes well on Firefox and less well on
Chrome, but Mover does ver well in older Chrome (faster than Lathe) and rather poorly on Firefox. It doesn't do
amazingly well in current Chrome versions, however, and Lathe beats it most of the time there. On 64-bit desktop or
server Java, you may want to prefer Mover64RNG
, which is the same algorithm using larger words and constants,
or MiniMover64RNG
, which is even faster but probably has a shorter period than this generator (millions of
seeds have been checked to ensure a minimum period of 2 to the 20 for it, though). While each of the two parts
of a Mover32RNG can have their full period evaluated, making the total period possible to calculate, the same cannot
be said for Mover64RNG or MiniMover64RNG (their maximum periods are high enough for most usage, but the actual totals
are still unknown).
setState(int)
is
used. setState() only allows 2 to the 32 starting states, but less than 2 to the 64 states are in the largest cycle,
so using a long or two ints to set the state seems ill-advised. The generator has two similar parts, each updated
without needing to read from the other part. Each is a 32-bit CMR generator, which multiplies a state by a constant,
rotates by another constant, and stores that as the next state. The particular constants used here were found by
randomly picking 16-bit odd numbers as multipliers, checking the period for every non-zero rotation, and reporting
the multiplier and rotation amount when a period was found that was greater than 0xFF000000. Better multipliers are
almost guaranteed to exist, but finding them would be a challenge.
Constructor and Description |
---|
Mover32RNG() |
Mover32RNG(int state) |
Mover32RNG(int stateA,
int stateB)
Not advised for external use; prefer
Mover32RNG(int) because it guarantees a good subcycle. |
Modifier and Type | Method and Description |
---|---|
Mover32RNG |
copy()
Produces a copy of this Mover32RNG 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()
Gets the "A" part of the state; if this generator was set with
Mover32RNG() , Mover32RNG(int) ,
or setState(int) , then this will be on the optimal subcycle, otherwise it may not be. |
int |
getStateB()
Gets the "B" part of the state; if this generator was set with
Mover32RNG() , Mover32RNG(int) ,
or setState(int) , then this will be on the optimal subcycle, otherwise it may not be. |
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() |
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 |
setState(int s) |
void |
setStateA(int stateA)
Sets the "A" part of the state to any int, which may put the generator in a low-period subcycle.
|
void |
setStateB(int stateB)
Sets the "B" part of the state to any int, which may put the generator in a low-period subcycle.
|
java.lang.String |
toString() |
public Mover32RNG()
public Mover32RNG(int state)
public Mover32RNG(int stateA, int stateB)
Mover32RNG(int)
because it guarantees a good subcycle. This
constructor allows all subcycles to be produced, including ones with a shorter period.stateA
- stateB
- public void setState(int s)
public int nextInt()
public int next(int bits)
RandomnessSource
next
in interface RandomnessSource
bits
- the number of bits to be returnedpublic long nextLong()
RandomnessSource
nextLong
in interface RandomnessSource
public Mover32RNG copy()
copy
in interface RandomnessSource
public int getStateA()
Mover32RNG()
, Mover32RNG(int)
,
or setState(int)
, then this will be on the optimal subcycle, otherwise it may not be.public int getStateB()
Mover32RNG()
, Mover32RNG(int)
,
or setState(int)
, then this will be on the optimal subcycle, otherwise it may not be.public void setStateA(int stateA)
setState(int)
to guarantee a good subcycle.stateA
- any intpublic void setStateB(int stateB)
setState(int)
to guarantee a good subcycle.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.