Package it.unich.jgmp
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_randclear
is only used internally; - the obsolete function
gmp_randinit
is not exposed by theRandState
class; - if the function name begins with
gmp_randinit
, we create a static method caleedbaseName
which returns a newRandState
object; - otherwise, we create a method
baseName
which calls the original function, implicitly usingthis
as the first non-constantgmp_randstate_t
parameter.
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 class
Cleaning action for theRandState
class. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate GmpRandstateT
The pointer to the nativegmp_randstate_t
object. -
Constructor Summary
ConstructorsModifierConstructorDescriptionBuilds the default random state.private
RandState
(GmpRandstateT pointer) A private constructor which build aRandState
starting 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 RandState
Returns the default random state.static RandState
randinitLc2Exp
(MPZ a, long c, long m2exp) Returns a random state for a linear congruential algorithm.static RandState
randinitLc2ExpSize
(long size) Returns a random state for a linear congruential algorithm.static RandState
Returns 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.long
urandombUi
(long n) Returns a uniformly distributed random number ofn
bits, in the range0
to(2n-1)
inclusive.long
urandommUi
(long n) Returns a uniformly distributed random number in the range0
to(n - 1)
inclusive.
-
Field Details
-
randstateNative
The pointer to the nativegmp_randstate_t
object.
-
-
Constructor Details
-
RandState
A private constructor which build aRandState
starting 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
- ifsize
is too big.
-
randinitSet
Returns a random state which is a copy ofop
. -
randseed
Sets an initial seed value into this. -
randseedUi
Sets an initial seed value into this. -
urandombUi
public long urandombUi(long n) Returns a uniformly distributed random number ofn
bits, in the range0
to(2n-1)
inclusive.n
must 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 range0
to(n - 1)
inclusive.
-