Class RandState
java.lang.Object
it.unich.jgmp.RandState
Current state of a random number generator. This class enapsulates the native
gmp_randstate_t data type, see the
Random Number Function page of the GMP manual. In determining
the names and signatures of the methods of the RandState class, we
adopted the following rules:
- the function
gmp_randclearis only used internally; - the obsolete function
gmp_randinitis not exposed by theRandStateclass; - if the function name begins with
gmp_randinit, we create a static method caleedbaseNamewhich returns a newRandStateobject; - otherwise, we create a method
baseNamewhich calls the original function, implicitly usingthisas the first non-constantgmp_randstate_tparameter.
In general, all the parameters which are not provided implicitly to the
original GMP function through this should be provided explicitly.
Note that it is not safe for two threads to generate a random number from the
same RandState simultaneously, since this involves an update of the
object.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classCleaning action for theRandStateclass. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate GmpRandstateTThe pointer to the nativegmp_randstate_tobject. -
Constructor Summary
ConstructorsModifierConstructorDescriptionBuilds the default random state.privateRandState(GmpRandstateT pointer) A private constructor which build aRandStatestarting from a pointer to its native data object.Builds a copy of the specified random state. -
Method Summary
Modifier and TypeMethodDescriptionReturns the native pointer to the GMP object.static RandStateReturns the default random state.static RandStaterandinitLc2Exp(MPZ a, long c, long m2exp) Returns a random state for a linear congruential algorithm.static RandStaterandinitLc2ExpSize(long size) Returns a random state for a linear congruential algorithm.static RandStateReturns a random state for a Mersenne Twister algorithm.randinitSet(RandState op) Returns a random state which is a copy ofop.Sets an initial seed value into this.randseedUi(long seed) Sets an initial seed value into this.longurandombUi(long n) Returns a uniformly distributed random number ofnbits, in the range0to(2n-1)inclusive.longurandommUi(long n) Returns a uniformly distributed random number in the range0to(n - 1)inclusive.
-
Field Details
-
randstateNative
The pointer to the nativegmp_randstate_tobject.
-
-
Constructor Details
-
RandState
A private constructor which build aRandStatestarting from a pointer to its native data object. The native object needs to be already initialized. -
RandState
public RandState()Builds the default random state. -
RandState
Builds a copy of the specified random state.
-
-
Method Details
-
getNative
Returns the native pointer to the GMP object. -
randinitDefault
Returns the default random state. -
randinitMt
Returns a random state for a Mersenne Twister algorithm. This algorithm is fast and has good randomness properties. -
randinitLc2Exp
Returns a random state for a linear congruential algorithm. See the GMP functiongmp_randinit_lc_2exp. -
randinitLc2ExpSize
Returns a random state for a linear congruential algorithm. See the GMP functiongmp_randinit_lc_2exp_size.- Throws:
IllegalArgumentException- ifsizeis too big.
-
randinitSet
-
randseed
-
randseedUi
Sets an initial seed value into this. -
urandombUi
public long urandombUi(long n) Returns a uniformly distributed random number ofnbits, in the range0to(2n-1)inclusive.nmust be less than or equal to the number of bits in a native unsigned long. -
urandommUi
public long urandommUi(long n) Returns a uniformly distributed random number in the range0to(n - 1)inclusive.
-