public class PermutedRNG extends Object implements RandomnessSource, StatefulRandomness
Modifier and Type | Field and Description |
---|---|
long |
state
The state can be seeded with any value.
|
Constructor and Description |
---|
PermutedRNG()
Creates a new generator seeded using Math.random.
|
PermutedRNG(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.
|
protected static long |
invert(long internal) |
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)
Calls nextLong() exactly one time.
|
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)
Calls nextLong() exactly one time.
|
int |
nextInt()
Can return any int, positive or negative, of any size permissible in a 32-bit signed integer.
|
int |
nextInt(int n)
Exclusive on the upper bound n.
|
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 n)
Exclusive on the upper bound n.
|
long |
nextLong(long lower,
long upper)
Exclusive on the upper bound n.
|
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 PermutedRNG's state without actually generating numbers.
|
String |
toString() |
public long state
public PermutedRNG()
public PermutedRNG(long seed)
public int next(int bits)
RandomnessSource
next
in interface RandomnessSource
bits
- the number of bits to be returnedpublic int nextInt()
public long nextLong()
nextLong
in interface RandomnessSource
public RandomnessSource copy()
copy
in interface RandomnessSource
protected static long invert(long internal)
public int nextInt(int n)
n
- 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 n)
n
- 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 PermutedRNG, as if it was constructed with this seed.public void setState(long seed)
setState
in interface StatefulRandomness
seed
- the seed to use for this PermutedRNG, 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.