Catalano.Math.Random
Class Pcg32
- java.lang.Object
-
- Catalano.Math.Random.Pcg32
-
- All Implemented Interfaces:
- IRandomNumberGenerator
public class Pcg32 extends java.lang.Object implements IRandomNumberGenerator
An instance of this class is used to generate a stream of pseudorandom numbers, similarly toRandom.The main differences are:
- PCG algorithm is used; in particular, this is a port of the minimal C implementation.
- Instances of Pcg32 are not thread-safe and so it doesn't obey
Randomcontract.
-
-
Constructor Summary
Constructors Constructor and Description Pcg32()Creates a new random number generator using current time (returned bySystem.nanoTime()) as the seed and a unique stream number.Pcg32(long initState, long initSeq)Creates a new random number generator using alongseed and alongstream number.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description intnextBits(int bits)Returns up to 32 random bits.booleannextBoolean()Returns the next pseudorandom, approximately uniformly distributedbooleanvalue.doublenextDouble()Returns the next pseudorandom, approximately uniformly distributeddoublevalue between 0.0 (inclusive) and 1.0 (exclusive).doublenextDouble(double bound)Returns the next pseudorandom, approximately uniformly distributeddoublevalue between 0.0 (inclusive) and bound (exclusive).voidnextDoubles(double[] d)Returns a vector of pseudorandom, uniformly distributed double values between 0.0 and 1.0 from this random number generator's sequence.floatnextFloat()Returns the next pseudorandom, approximately uniformly distributedfloatvalue between 0.0 (inclusive) and 1.0 (exclusive).floatnextFloat(float bound)Returns the next pseudorandom, approximately uniformly distributedfloatvalue between 0.0 (inclusive) and bound (exclusive).doublenextGaussian()Returns the next pseudorandom, Gaussian ("normally") distributeddoublevalue with mean0.0and standard deviation1.0from this random number generator's sequence.doublenextGaussian(double mean, double standardDeviation)Returns the next pseudorandom, Gaussian ("normally") distributeddoublevalue with given mean and standard deviation from this random number generator's sequence.intnextInt()Returns the next pseudorandom, approximately uniformly distributedintvalue from this random number generator's sequence.intnextInt(int n)Returns the next pseudorandom, approximately uniformly distributedintvalue between 0 (inclusive) andn(exclusive).longnextLong()Returns the next pseudorandom, approximately uniformly distributedlongvalue from this random number generator's sequence.longnextLong(long n)Returns the next pseudorandom, approximately uniformly distributedlongvalue between 0 (inclusive) andn(exclusive).voidseed()Initializes the generator with current time as the state and a (very likely to be) unique stream number.voidseed(long initState, long initSeq)voidsetSeed(long seed)Set seed.
-
-
-
Constructor Detail
-
Pcg32
public Pcg32(long initState, long initSeq)Creates a new random number generator using alongseed and alongstream number.The invocation
new Pcg32(initState, initSeq)is equivalent to:Pcg32 rnd = new Pcg32(); rnd.seed(initState, initSeq);- See Also:
seed(long, long)
-
Pcg32
public Pcg32()
Creates a new random number generator using current time (returned bySystem.nanoTime()) as the seed and a unique stream number.- See Also:
seed()
-
-
Method Detail
-
setSeed
public void setSeed(long seed)
Description copied from interface:IRandomNumberGeneratorSet seed.- Specified by:
setSeedin interfaceIRandomNumberGenerator- Parameters:
seed- Seed.
-
nextInt
public int nextInt()
Returns the next pseudorandom, approximately uniformly distributedintvalue from this random number generator's sequence. The general contract ofnextIntis that oneintvalue is pseudorandomly generated and returned. All 232 possibleintvalues are produced with (approximately) equal probability.- Specified by:
nextIntin interfaceIRandomNumberGenerator- See Also:
Random.nextInt()
-
nextInt
public int nextInt(int n)
Returns the next pseudorandom, approximately uniformly distributedintvalue between 0 (inclusive) andn(exclusive).- Specified by:
nextIntin interfaceIRandomNumberGenerator- See Also:
Random.nextInt(int)
-
nextLong
public long nextLong()
Returns the next pseudorandom, approximately uniformly distributedlongvalue from this random number generator's sequence. The general contract ofnextLongis that onelongvalue is pseudorandomly generated and returned. All 264 possiblelongvalues are produced with (approximately) equal probability.- Specified by:
nextLongin interfaceIRandomNumberGenerator- See Also:
Random.nextLong()
-
nextLong
public long nextLong(long n)
Returns the next pseudorandom, approximately uniformly distributedlongvalue between 0 (inclusive) andn(exclusive).- Returns:
-
nextBoolean
public boolean nextBoolean()
Returns the next pseudorandom, approximately uniformly distributedbooleanvalue.- See Also:
Random.nextBoolean()
-
nextFloat
public float nextFloat()
Returns the next pseudorandom, approximately uniformly distributedfloatvalue between 0.0 (inclusive) and 1.0 (exclusive).- See Also:
Random.nextFloat()
-
nextFloat
public float nextFloat(float bound)
Returns the next pseudorandom, approximately uniformly distributedfloatvalue between 0.0 (inclusive) and bound (exclusive).
-
nextDouble
public double nextDouble()
Returns the next pseudorandom, approximately uniformly distributeddoublevalue between 0.0 (inclusive) and 1.0 (exclusive).- Specified by:
nextDoublein interfaceIRandomNumberGenerator- See Also:
Random.nextDouble()
-
nextDouble
public double nextDouble(double bound)
Returns the next pseudorandom, approximately uniformly distributeddoublevalue between 0.0 (inclusive) and bound (exclusive).
-
nextBits
public int nextBits(int bits)
Description copied from interface:IRandomNumberGeneratorReturns up to 32 random bits.- Specified by:
nextBitsin interfaceIRandomNumberGenerator
-
nextGaussian
public double nextGaussian()
Returns the next pseudorandom, Gaussian ("normally") distributeddoublevalue with mean0.0and standard deviation1.0from this random number generator's sequence.- See Also:
Random.nextGaussian()
-
nextGaussian
public double nextGaussian(double mean, double standardDeviation)Returns the next pseudorandom, Gaussian ("normally") distributeddoublevalue with given mean and standard deviation from this random number generator's sequence.
-
seed
public void seed(long initState, long initSeq)
-
seed
public void seed()
Initializes the generator with current time as the state and a (very likely to be) unique stream number. This ensures that even if multiple generators are initialized using this method whileSystem.nanoTime()returns the same time, they will have different sequences.
-
nextDoubles
public void nextDoubles(double[] d)
Description copied from interface:IRandomNumberGeneratorReturns a vector of pseudorandom, uniformly distributed double values between 0.0 and 1.0 from this random number generator's sequence.- Specified by:
nextDoublesin interfaceIRandomNumberGenerator
-
-
DataMelt 3.0 © DataMelt by jWork.ORG