Package gmp
Class RandState
java.lang.Object
gmp.RandState
Pseudo-random number generation states.
A RandState object wraps a gmp_randstate_t
GMP object, i.e.,
a state for pseudo-random number generation functions.
The state defines an algorithm and a current value state (that should be
seeded).
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a random state with the default algorithm.RandState
(boolean b) Creates a random state for a Mersenne Twister algorithm.RandState
(int size) Creates a random state for a congruential algorithm.Creates a random state for a congruential algorithm.Creates a copy of the random state op. -
Method Summary
Modifier and TypeMethodDescriptionint
randomBits
(int n) Returns an uniformly distributed random number of n bits (i.e., in 0..2^n-1).int
randomInt
(int n) Returns an uniformly distributed random number in 0..n-1.void
Seed
(int seed) Sets an initial seed value for the state.void
Sets an initial seed value for the state.
-
Constructor Details
-
RandState
public RandState()Creates a random state with the default algorithm. -
RandState
public RandState(boolean b) Creates a random state for a Mersenne Twister algorithm.The boolean argument is not actually used. It is used to differentiate from the default algorithm constructor.
-
RandState
Creates a random state for a congruential algorithm.X=(aX+c) mod 2^m2exp.
-
RandState
public RandState(int size) Creates a random state for a congruential algorithm.The multiplicand and modulo are selected from a table to ensure that at least size bits of each value is used.
The maximum size currently supported is 128.
-
RandState
Creates a copy of the random state op.
-
-
Method Details
-
Seed
Sets an initial seed value for the state. -
Seed
public void Seed(int seed) Sets an initial seed value for the state. -
randomBits
public int randomBits(int n) Returns an uniformly distributed random number of n bits (i.e., in 0..2^n-1).n must be positive.
-
randomInt
public int randomInt(int n) Returns an uniformly distributed random number in 0..n-1.n must be positive.
-