public class LightRNG extends Object implements RandomnessSource, StatefulRandomness
Modifier and Type | Field and Description |
---|---|
long |
state |
Constructor and Description |
---|
LightRNG()
Creates a new generator seeded using Math.random.
|
LightRNG(long seed) |
Modifier and Type | Method and Description |
---|---|
RandomnessSource |
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.
|
long |
getState()
Gets the current state of this generator.
|
int |
next(int bits)
Using this method, any algorithm that might use the built-in Java Random
can interface with this randomness source.
|
boolean |
nextBoolean()
Gets a random value, true or false.
|
void |
nextBytes(byte[] bytes)
Given a byte array as a parameter, this will fill the array with random bytes (modifying it
in-place).
|
double |
nextDouble()
Gets a uniform random double in the range [0.0,1.0)
|
double |
nextDouble(double outer)
Gets a uniform random double in the range [0.0,outer) given a positive parameter outer.
|
float |
nextFloat()
Gets a uniform random float in the range [0.0,1.0)
|
int |
nextInt()
Can return any int, positive or negative, of any size permissible in a 32-bit signed integer.
|
int |
nextInt(int bound)
Exclusive on the upper bound.
|
int |
nextInt(int lower,
int upper)
Inclusive lower, exclusive upper.
|
long |
nextLong()
Can return any long, positive or negative, of any size permissible in a 64-bit signed integer.
|
long |
nextLong(long bound)
Exclusive on the upper bound.
|
long |
nextLong(long lower,
long upper)
Inclusive lower, exclusive upper.
|
void |
setSeed(long seed)
Sets the seed of this generator (which is also the current state).
|
void |
setState(long seed)
Sets the seed (also the current state) of this generator.
|
long |
skip(long advance)
Advances or rolls back the LightRNG's state without actually generating numbers.
|
String |
toString() |
public long state
public LightRNG()
public LightRNG(long seed)
public int next(int bits)
RandomnessSource
next
in interface RandomnessSource
bits
- the number of bits to be returnedpublic long nextLong()
nextLong
in interface RandomnessSource
public RandomnessSource copy()
copy
in interface RandomnessSource
public int nextInt()
public int nextInt(int bound)
bound
- the upper bound; should be positivepublic int nextInt(int lower, int upper)
lower
- the lower bound, inclusive, can be positive or negativeupper
- the upper bound, exclusive, should be positive, must be greater than lowerpublic long nextLong(long bound)
bound
- the upper bound; should be positivepublic long nextLong(long lower, long upper)
lower
- the lower bound, inclusive, can be positive or negativeupper
- the upper bound, exclusive, should be positive, must be greater than lowerpublic double nextDouble()
public double nextDouble(double outer)
outer
- the exclusive outer bound, can be negativepublic float nextFloat()
public boolean nextBoolean()
public void nextBytes(byte[] bytes)
Math.ceil(bytes.length / 8.0)
times.bytes
- a byte array that will have its contents overwritten with random bytes.public void setSeed(long seed)
seed
- the seed to use for this LightRNG, as if it was constructed with this seed.public void setState(long seed)
setState
in interface StatefulRandomness
seed
- the seed to use for this LightRNG, as if it was constructed with this seed.public long getState()
getState
in interface StatefulRandomness
public long skip(long advance)
advance
- Number of future generations to skip past. Can be negative to backtrack.Copyright © 2012–2016. All rights reserved.