public class RomuTrioRNG extends java.lang.Object implements RandomnessSource, java.io.Serializable
long
states, which must never all be 0 but otherwise have no known restrictions.
setSeed(long)
instead of
setState(long, long, long)
, because if you give sequential seeds to both setSeed() and setState(), the
former will start off random, while the latter will start off repeating the seed sequence. After about 20-40 random
numbers generated, any correlation between similarly seeded generators will probably be completely gone, though.Modifier and Type | Field and Description |
---|---|
protected long |
stateA
The first state; can be any long unless all states are 0.
|
protected long |
stateB
The second state; can be any long; can be any long unless all states are 0.
|
protected long |
stateC
The third state; can be any long; can be any long unless all states are 0.
|
Constructor and Description |
---|
RomuTrioRNG()
Creates a new RomuTrioRNG with a random state.
|
RomuTrioRNG(long seed)
Creates a new RomuTrioRNG with the given seed; all
long values are permitted. |
RomuTrioRNG(long stateA,
long stateB,
long stateC)
Creates a new RomuTrioRNG with the given three states; all
long values are permitted unless all
three states are 0. |
Modifier and Type | Method and Description |
---|---|
RomuTrioRNG |
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 |
getSelectedState(int selection)
Gets the state determined by
selection , as-is. |
long |
getStateA() |
long |
getStateB() |
long |
getStateC() |
int |
getStateCount()
This generator has 3
long states, so this returns 3. |
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 all 3 states of the generator to random values based on the given seed.
|
void |
setSelectedState(int selection,
long value)
Sets one of the states, determined by
selection , to value , as-is. |
void |
setState(long stateA,
long stateB,
long stateC)
Sets the state completely to the given three state variables.
|
void |
setStateA(long stateA)
Sets the first part of the state.
|
void |
setStateB(long stateB)
Sets the second part of the state.
|
void |
setStateC(long stateC)
Sets the third part of the state; if all states would be 0, this instead assigns -1.
|
java.lang.String |
toString() |
protected long stateA
nextLong()
will return that value as-is. Later calls will be more random.protected long stateB
protected long stateC
public RomuTrioRNG()
public RomuTrioRNG(long seed)
long
values are permitted.
The seed will be passed to setSeed(long)
to attempt to adequately distribute the seed randomly.seed
- any long
valuepublic RomuTrioRNG(long stateA, long stateB, long stateC)
long
values are permitted unless all
three states are 0. In that case, it treats stateC as if it were -1. Otherwise, these states will be used verbatim.stateA
- any long
valuestateB
- any long
valuestateC
- any long
valuepublic int getStateCount()
long
states, so this returns 3.public long getSelectedState(int selection)
selection
, as-is.selection
- used to select which state variable to get; generally 0, 1, or 2public void setSelectedState(int selection, long value)
selection
, to value
, as-is.
Selections 0, 1, and 2 refer to states A, B, and C, and if the selection is anything
else, this treats it as 2 and sets stateC.selection
- used to select which state variable to set; generally 0, 1, or 2value
- the exact value to use for the selected state, if validpublic 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 getStateA()
public void setStateA(long stateA)
nextLong()
immediately after this, it will return the given stateA
as-is, so you
may want to call some random generation methods (such as nextLong()) and discard
the results after setting the state.stateA
- can be any longpublic long getStateB()
public void setStateB(long stateB)
stateB
- can be any longpublic long getStateC()
public void setStateC(long stateC)
stateC
- can be any longpublic void setState(long stateA, long stateB, long stateC)
setStateA(long)
, setStateB(long)
,
and setStateC(long)
as a group. You may want to call nextLong()
a few times after setting the states like this, unless the value for stateA (in
particular) is already adequately random; the first call to nextLong()
,
if it is made immediately after calling this, will return stateA
as-is.stateA
- the first state; this will be returned as-is if the next call is to nextLong()
stateB
- the second state; can be any longstateC
- the third state; can be any longpublic long nextLong()
RandomnessSource
nextLong
in interface RandomnessSource
public int next(int bits)
RandomnessSource
next
in interface RandomnessSource
bits
- the number of bits to be returnedpublic RomuTrioRNG copy()
RandomnessSource
copy
in interface RandomnessSource
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
Copyright © Eben Howard 2012–2022. All rights reserved.