Package it.unich.jgmp
Class RandState
- java.lang.Object
-
- it.unich.jgmp.RandState
-
public class RandState extends java.lang.Object
Current state of a random number generator. This class enapsulates the nativegmp_randstate_t
data type, see the Random Number Function page of the GMP manual. In determining the names and signatures of the methods of theRandState
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. - the function
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
RandState.RandomStateCleaner
Cleaning action for theRandState
class.
-
Field Summary
Fields Modifier and Type Field Description private GmpRandstateT
randstateNative
The pointer to the nativegmp_randstate_t
object.
-
Constructor Summary
Constructors Modifier Constructor Description RandState()
Builds the default random state.private
RandState(GmpRandstateT pointer)
A private constructor which build aRandState
starting from a pointer to its native data object.RandState(RandState state)
Builds a copy of the specified random state.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description GmpRandstateT
getNative()
Returns the native pointer to the GMP object.static RandState
randinitDefault()
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
randinitMt()
Returns a random state for a Mersenne Twister algorithm.RandState
randinitSet(RandState op)
Returns a random state which is a copy ofop
.RandState
randseed(MPZ seed)
Sets an initial seed value into this.RandState
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 Detail
-
randstateNative
private GmpRandstateT randstateNative
The pointer to the nativegmp_randstate_t
object.
-
-
Constructor Detail
-
RandState
private RandState(GmpRandstateT pointer)
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
public RandState(RandState state)
Builds a copy of the specified random state.
-
-
Method Detail
-
getNative
public GmpRandstateT getNative()
Returns the native pointer to the GMP object.
-
randinitDefault
public static RandState randinitDefault()
Returns the default random state.
-
randinitMt
public static RandState randinitMt()
Returns a random state for a Mersenne Twister algorithm. This algorithm is fast and has good randomness properties.
-
randinitLc2Exp
public static RandState randinitLc2Exp(MPZ a, long c, long m2exp)
Returns a random state for a linear congruential algorithm. See the GMP functiongmp_randinit_lc_2exp
.
-
randinitLc2ExpSize
public static RandState randinitLc2ExpSize(long size)
Returns a random state for a linear congruential algorithm. See the GMP functiongmp_randinit_lc_2exp_size
.- Throws:
java.lang.IllegalArgumentException
- ifsize
is too big.
-
randinitSet
public RandState randinitSet(RandState op)
Returns a random state which is a copy ofop
.
-
randseedUi
public RandState randseedUi(long seed)
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.
-
-