public class ConstantRandom
extends java.util.Random
Modifier and Type | Field and Description |
---|---|
static ConstantRandom |
MAXIMUM
A random number generator that always returns the largest possible value.
|
static ConstantRandom |
MINIMUM
A random number generator that always returns the lowest possible value.
|
Constructor and Description |
---|
ConstantRandom(byte wrapValue)
Constructs a random generator that uses an infinite stream of bytes as the source of "randomness".
|
ConstantRandom(byte[] data)
Constructs a random generator from a given byte source, starting at the given bit offset.
|
ConstantRandom(byte[] data,
boolean wrapAround)
Constructs a random generator from a given byte source, starting at the given bit offset.
|
ConstantRandom(byte[] data,
boolean wrapAround,
int offset)
Constructs a random generator from a given byte source, starting at the given bit offset.
|
Modifier and Type | Method and Description |
---|---|
byte[] |
getData()
Retrieves the bit array we're using as a source for our random numbers.
|
int |
getIndex()
Retrieves the bit index in the byte array we're reading from.
|
boolean |
isWrapAround()
Whether or not we wrap around after reaching the end of the byte array.
|
protected int |
next(int bits) |
int |
nextInt(int n) |
void |
setData(byte[] data)
Sets the bit array, represented as a byte array, we'll use as a source for our random numbers.
|
void |
setIndex(int index)
Sets the bit index in the byte array we're reading from.
|
void |
setWrapAround(boolean wrapAround)
Whether or not we wrap around after reaching the end of the byte array.
|
public static ConstantRandom MAXIMUM
public static ConstantRandom MINIMUM
public ConstantRandom(byte[] data)
data
- - source of bytes to use in the random number generator.public ConstantRandom(byte wrapValue)
wrapValue
- - the value that will be copied infinitely in the stream.public ConstantRandom(byte[] data, boolean wrapAround)
data
- - source of bytes to use in the random number generator.wrapAround
- - TRUE to wrap around when the reader has reached the last byte element, FALSE to raise an exception.public ConstantRandom(byte[] data, boolean wrapAround, int offset)
data
- - source of bytes to use in the random number generator.wrapAround
- - TRUE to wrap around when the reader has reached the last byte element, FALSE to raise an exception.offset
- - the bit to start reading from.public int nextInt(int n)
nextInt
in class java.util.Random
protected int next(int bits)
next
in class java.util.Random
public byte[] getData()
public void setData(byte[] data)
data
- - new byte array to use.public int getIndex()
public void setIndex(int index)
index
- - new bit index in the array.public void setWrapAround(boolean wrapAround)
wrapAround
- - TRUE to wrap around, FALSE to raise an exception.public boolean isWrapAround()