public class Pcg32 extends java.lang.Object implements IRandomNumberGenerator
Random.
The main differences are:
Random contract.| Constructor and Description |
|---|
Pcg32()
Creates a new random number generator using current time (returned by
System.nanoTime()) as the seed
and a unique stream number. |
Pcg32(long initState,
long initSeq)
Creates a new random number generator using a
long seed and a long stream number. |
| Modifier and Type | Method and Description |
|---|---|
int |
nextBits(int bits)
Returns up to 32 random bits.
|
boolean |
nextBoolean()
Returns the next pseudorandom, approximately uniformly distributed
boolean value. |
double |
nextDouble()
Returns the next pseudorandom, approximately uniformly distributed
double value between 0.0 (inclusive)
and 1.0 (exclusive). |
double |
nextDouble(double bound)
Returns the next pseudorandom, approximately uniformly distributed
double value between 0.0 (inclusive)
and bound (exclusive). |
void |
nextDoubles(double[] d)
Returns a vector of pseudorandom, uniformly distributed double values
between 0.0 and 1.0 from this random number generator's sequence.
|
float |
nextFloat()
Returns the next pseudorandom, approximately uniformly distributed
float value between 0.0 (inclusive)
and 1.0 (exclusive). |
float |
nextFloat(float bound)
Returns the next pseudorandom, approximately uniformly distributed
float value between 0.0 (inclusive)
and bound (exclusive). |
double |
nextGaussian()
Returns the next pseudorandom, Gaussian ("normally") distributed
double value with mean 0.0 and standard
deviation 1.0 from this random number generator's sequence. |
double |
nextGaussian(double mean,
double standardDeviation)
Returns the next pseudorandom, Gaussian ("normally") distributed
double value with given mean and standard
deviation from this random number generator's sequence. |
int |
nextInt()
Returns the next pseudorandom, approximately uniformly distributed
int
value from this random number generator's sequence. |
int |
nextInt(int n)
Returns the next pseudorandom, approximately uniformly distributed
int
value between 0 (inclusive) and n (exclusive). |
long |
nextLong()
Returns the next pseudorandom, approximately uniformly distributed
long
value from this random number generator's sequence. |
long |
nextLong(long n)
Returns the next pseudorandom, approximately uniformly distributed
long
value between 0 (inclusive) and n (exclusive). |
void |
seed()
Initializes the generator with current time as the state and
a (very likely to be) unique stream number.
|
void |
seed(long initState,
long initSeq) |
void |
setSeed(long seed)
Set seed.
|
public Pcg32(long initState,
long initSeq)
long seed and a long stream number.
The invocation new Pcg32(initState, initSeq) is equivalent to:
Pcg32 rnd = new Pcg32();
rnd.seed(initState, initSeq);
seed(long, long)public Pcg32()
System.nanoTime()) as the seed
and a unique stream number.seed()public void setSeed(long seed)
IRandomNumberGeneratorsetSeed in interface IRandomNumberGeneratorseed - Seed.public int nextInt()
int
value from this random number generator's sequence. The general
contract of nextInt is that one int value is
pseudorandomly generated and returned. All 232
possible int values are produced with
(approximately) equal probability.nextInt in interface IRandomNumberGeneratorRandom.nextInt()public int nextInt(int n)
int
value between 0 (inclusive) and n (exclusive).nextInt in interface IRandomNumberGeneratorRandom.nextInt(int)public long nextLong()
long
value from this random number generator's sequence. The general
contract of nextLong is that one long value is
pseudorandomly generated and returned. All 264
possible long values are produced with
(approximately) equal probability.nextLong in interface IRandomNumberGeneratorRandom.nextLong()public long nextLong(long n)
long
value between 0 (inclusive) and n (exclusive).public boolean nextBoolean()
boolean value.Random.nextBoolean()public float nextFloat()
float value between 0.0 (inclusive)
and 1.0 (exclusive).Random.nextFloat()public float nextFloat(float bound)
float value between 0.0 (inclusive)
and bound (exclusive).public double nextDouble()
double value between 0.0 (inclusive)
and 1.0 (exclusive).nextDouble in interface IRandomNumberGeneratorRandom.nextDouble()public double nextDouble(double bound)
double value between 0.0 (inclusive)
and bound (exclusive).public int nextBits(int bits)
IRandomNumberGeneratornextBits in interface IRandomNumberGeneratorpublic double nextGaussian()
double value with mean 0.0 and standard
deviation 1.0 from this random number generator's sequence.Random.nextGaussian()public double nextGaussian(double mean,
double standardDeviation)
double value with given mean and standard
deviation from this random number generator's sequence.public void seed(long initState,
long initSeq)
public void seed()
System.nanoTime() returns the same time, they
will have different sequences.public void nextDoubles(double[] d)
IRandomNumberGeneratornextDoubles in interface IRandomNumberGenerator