Package smile.math.random
Class UniversalGenerator
java.lang.Object
smile.math.random.UniversalGenerator
- All Implemented Interfaces:
RandomNumberGenerator
The so-called "Universal Generator" based on multiplicative congruential
method, which originally appeared in "Toward a Universal Random Number
Generator" by Marsaglia, Zaman and Tsang. It was later modified by F. James
in "A Review of Pseudo-random Number Generators". It passes ALL the tests
for random number generators and has a period of 2144. It is
completely portable (gives bit-identical results on all machines with at
least 24-bit mantissas in the floating point representation).
-
Constructor Summary
ConstructorDescriptionInitialize Random with default seed.UniversalGenerator
(int seed) Initialize Random with a specified integer seedUniversalGenerator
(long seed) Initialize Random with a specified long seed -
Method Summary
Modifier and TypeMethodDescriptionint
next
(int numbits) Returns up to 32 random bits.double
Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 from this random number generator's sequence.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.int
nextInt()
Returns the next pseudorandom, uniformly distributed int value from this random number generator's sequence.int
nextInt
(int n) Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.long
nextLong()
Returns the next pseudorandom, uniformly distributed long value from this random number generator's sequence.void
setSeed
(long seed) Initialize the random generator with a seed.
-
Constructor Details
-
UniversalGenerator
public UniversalGenerator()Initialize Random with default seed. -
UniversalGenerator
public UniversalGenerator(int seed) Initialize Random with a specified integer seed- Parameters:
seed
- the seed of random numbers.
-
UniversalGenerator
public UniversalGenerator(long seed) Initialize Random with a specified long seed- Parameters:
seed
- the seed of random numbers.
-
-
Method Details
-
setSeed
public void setSeed(long seed) Description copied from interface:RandomNumberGenerator
Initialize the random generator with a seed.- Specified by:
setSeed
in interfaceRandomNumberGenerator
- Parameters:
seed
- the seed of random numbers.
-
nextDouble
public double nextDouble()Description copied from interface:RandomNumberGenerator
Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 from this random number generator's sequence.- Specified by:
nextDouble
in interfaceRandomNumberGenerator
- Returns:
- random number.
-
nextDoubles
public void nextDoubles(double[] d) Description copied from interface:RandomNumberGenerator
Returns a vector of pseudorandom, uniformly distributed double values between 0.0 and 1.0 from this random number generator's sequence.- Specified by:
nextDoubles
in interfaceRandomNumberGenerator
- Parameters:
d
- the output random numbers.
-
next
public int next(int numbits) Description copied from interface:RandomNumberGenerator
Returns up to 32 random bits.- Specified by:
next
in interfaceRandomNumberGenerator
- Parameters:
numbits
- the number of random bits to generate.- Returns:
- random bits.
-
nextInt
public int nextInt()Description copied from interface:RandomNumberGenerator
Returns the next pseudorandom, uniformly distributed int value from this random number generator's sequence.- Specified by:
nextInt
in interfaceRandomNumberGenerator
- Returns:
- random number.
-
nextInt
public int nextInt(int n) Description copied from interface:RandomNumberGenerator
Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.- Specified by:
nextInt
in interfaceRandomNumberGenerator
- Parameters:
n
- the upper bound of random number (exclusive).- Returns:
- random number.
-
nextLong
public long nextLong()Description copied from interface:RandomNumberGenerator
Returns the next pseudorandom, uniformly distributed long value from this random number generator's sequence.- Specified by:
nextLong
in interfaceRandomNumberGenerator
- Returns:
- random number.
-