public class SpecifiedRandomness extends java.lang.Object implements StatefulRandomness, java.io.Serializable
nextLong()
and/or next(int)
are called. This is meant for testing corner-case bugs in any kind of procedural
generation, where certain, possibly very rare, number sequences at points in a program cause issues.
Rather than rely on finding a seed that, at just the right point in its sequence, causes such a problem,
you can use a SpecifiedRandomness that could cause the problem right away so it can be debugged.
Constructor and Description |
---|
SpecifiedRandomness()
Constructs a SpecifiedRandomness that will produce the sequence:
-1, 0, 9223372036854775807, -9223372036854775808
in a cycle. |
SpecifiedRandomness(long... results)
Constructs a SpecifiedRandomness given a non-null, non-empty array or vararg of long results.
|
SpecifiedRandomness(SpecifiedRandomness other)
Copies the given SpecifiedRandomness into a new one, using the same state and results sequence.
|
Modifier and Type | Method and Description |
---|---|
SpecifiedRandomness |
copy()
Produces a copy of this SpecifiedRandomness 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.
|
long |
getState()
Get the current internal state of the StatefulRandomness as a long.
|
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 |
setState(long state)
Set the current internal state of this StatefulRandomness with a long.
|
public SpecifiedRandomness()
-1, 0, 9223372036854775807, -9223372036854775808
in a cycle.public SpecifiedRandomness(long... results)
results
- a non-null, non-empty array or vararg of long to use as the sequence this producespublic SpecifiedRandomness(SpecifiedRandomness other)
other
- another, non-null, SpecifiedRandomness to deep-copy into thispublic 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 long getState()
getState
in interface StatefulRandomness
public void setState(long state)
setState
in interface StatefulRandomness
state
- any 64-bit long.public SpecifiedRandomness copy()
copy
in interface RandomnessSource
copy
in interface StatefulRandomness
Copyright © Eben Howard 2012–2022. All rights reserved.