public class LCG64ShiftRandom extends Random64
iff b is odd and a
mod 4 = 1.
This is an re-implementation of the trng::lcg64_shift PRNG class of the TRNG library created by Heiko Bauke.
Not that the base implementation of the LCG64ShiftRandom
class is not thread-safe. If multiple threads requests random
numbers from this class, it must be synchronized externally.
Alternatively you can use the thread-safe implementations
LCG64ShiftRandom.ThreadSafe or LCG64ShiftRandom.ThreadLocal.
RandomRegistry,
Serialized Form| Modifier and Type | Class and Description |
|---|---|
static class |
LCG64ShiftRandom.Param
Parameter class for the
LCG64ShiftRandom generator, for the
parameters a and b of the LC recursion
ri+1 = a · ri + b mod 264. |
static class |
LCG64ShiftRandom.ThreadLocal
This class represents a thread local implementation of the
LCG64ShiftRandom PRNG. |
static class |
LCG64ShiftRandom.ThreadSafe
This is a thread safe variation of the this PRNG—by
synchronizing the random number generation.
|
| Constructor and Description |
|---|
LCG64ShiftRandom()
Create a new PRNG instance with
LCG64ShiftRandom.Param.DEFAULT parameter and safe
seed. |
LCG64ShiftRandom(LCG64ShiftRandom.Param param)
Create a new PRNG instance with the given parameter and a safe seed
|
LCG64ShiftRandom(LCG64ShiftRandom.Param param,
long seed)
Create a new PRNG instance with the given parameter and seed.
|
LCG64ShiftRandom(long seed)
Create a new PRNG instance with
LCG64ShiftRandom.Param.DEFAULT parameter and the
given seed. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object obj) |
LCG64ShiftRandom.Param |
getParam() |
int |
hashCode() |
void |
jump(long step)
Changes the internal state of the PRNG in such a way that the engine
jumps s steps ahead.
|
void |
jump2(int s)
Changes the internal state of the PRNG in such a way that the engine
jumps 2s steps ahead.
|
double |
nextDouble(double min,
double max)
Returns a pseudorandom, uniformly distributed double value between
min (inclusively) and max (exclusively).
|
float |
nextFloat(float min,
float max)
Returns a pseudorandom, uniformly distributed double value between
min (inclusively) and max (exclusively).
|
int |
nextInt(int min,
int max)
Returns a pseudorandom, uniformly distributed int value between min and
max (end points included).
|
long |
nextLong()
Force to explicitly override the Random.nextLong() method.
|
long |
nextLong(long n)
Returns a pseudorandom, uniformly distributed int value between 0
(inclusive) and the specified value (exclusive), drawn from the given
random number generator's sequence.
|
long |
nextLong(long min,
long max)
Returns a pseudorandom, uniformly distributed int value between min
and max (end points included).
|
void |
setSeed(long seed) |
void |
split(int p,
int s)
Changes the internal state of the PRNG in a way that future calls to
nextLong() will generated the sth sub-stream of
pth sub-streams. |
String |
toString() |
next, nextBoolean, nextBytes, nextDouble, nextFloat, nextInt, ofpublic LCG64ShiftRandom(LCG64ShiftRandom.Param param, long seed)
param - the parameter of the PRNG.seed - the seed of the PRNG.NullPointerException - if the given param is null.public LCG64ShiftRandom(LCG64ShiftRandom.Param param)
param - the PRNG parameter.NullPointerException - if the given param is null.public LCG64ShiftRandom(long seed)
LCG64ShiftRandom.Param.DEFAULT parameter and the
given seed.seed - the seed of the PRNGpublic LCG64ShiftRandom()
LCG64ShiftRandom.Param.DEFAULT parameter and safe
seed.public long nextLong()
Random64public void split(int p, int s)
nextLong() will generated the sth sub-stream of
pth sub-streams. s must be within the range of
[0, p-1). This method is mainly used for parallelization
via leap-frogging.p - the overall number of sub-streamss - the sth sub-streamIllegalArgumentException - if p < 1 || s >= p.public void jump2(int s)
s - the 2s steps to jump ahead.IllegalArgumentException - if s < 0.public void jump(long step)
step - the steps to jump ahead.IllegalArgumentException - if s < 0.public LCG64ShiftRandom.Param getParam()
public int nextInt(int min, int max)
min - lower bound for generated integer (inclusively)max - upper bound for generated integer (inclusively)min and less
than or equal to maxIllegalArgumentException - if min >= maxrandom.nextInt(java.util.Random, int, int)public long nextLong(long min, long max)
min - lower bound for generated long integer (inclusively)max - upper bound for generated long integer (inclusively)min
and less than or equal to maxIllegalArgumentException - if min >= maxrandom.nextLong(java.util.Random, long, long)public long nextLong(long n)
n - the bound on the random number to be returned. Must be
positive.IllegalArgumentException - if n is smaller than 1.random.nextLong(java.util.Random, long)public float nextFloat(float min, float max)
min - lower bound for generated float value (inclusively)max - upper bound for generated float value (exclusively)min and less
than to maxrandom.nextFloat(java.util.Random, float, float)public double nextDouble(double min, double max)
min - lower bound for generated double value (inclusively)max - upper bound for generated double value (exclusively)min and less
than to maxrandom.nextDouble(java.util.Random, double, double)© 2007-2016 Franz Wilhelmstötter (2016-04-24 10:25)