public class TangleRNG extends java.lang.Object implements RandomnessSource, SkippingRandomness, java.io.Serializable
OrbitRNG
, which gives up more speed but moves through all 2 to the 64 long values as streams over
its full period, which is 2 to the 128 (with one stream) instead of the 2 to the 64 (with 2 to the 63 streams) here.
There's also SilkRNG
, which is like OrbitRNG but uses 32-bit math and is GWT-optimized.
getStream()
, which may
have a use somewhere (maybe diagnosing possible problems?).
Constructor and Description |
---|
TangleRNG()
Creates a new generator seeded using Math.random.
|
TangleRNG(long seed) |
TangleRNG(long seedA,
long seedB) |
Modifier and Type | Method and Description |
---|---|
TangleRNG |
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.
|
long |
getStream()
Gets a long that identifies which stream of numbers this generator is producing; this stream identifier is always
an odd long and won't change by generating numbers.
|
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; the least significant bit is ignored (will always be odd).
|
long |
skip(long advance)
Advances or rolls back the SkippingRandomness' state without actually generating each number.
|
java.lang.String |
toString() |
public TangleRNG()
public TangleRNG(long seed)
public TangleRNG(long seedA, long seedB)
public long getStateA()
public void setStateA(long stateA)
stateA
- a 64-bit longpublic long getStateB()
public void setStateB(long stateB)
stateB
- a 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 TangleRNG 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
public long skip(long advance)
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 nextLong()
.skip
in interface SkippingRandomness
advance
- Number of future generations to skip over; can be negative to backtrack, 0 gets the most-recently-generated numberadvance
numberspublic long getStream()
setStateA(long)
or setStateB(long)
are called. Each stream is a
probably-unique sequence of 2 to the 64 longs, where approximately 1/3 of all possible longs will not ever occur
(while others occur twice or more), but this set of results is different for every stream. There are 2 to the 63
possible streams, one for every odd long.Copyright © Eben Howard 2012–2022. All rights reserved.