Package it.unich.jgmp
Class RandState
- java.lang.Object
-
- it.unich.jgmp.RandState
-
public class RandState extends java.lang.ObjectCurrent state of a random number generator. This class enapsulates the nativegmp_randstate_tdata type, see the Random Number Function page of the GMP manual. In determining the names and signatures of the methods of theRandStateclass, 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
thisshould be provided explicitly.Note that it is not safe for two threads to generate a random number from the same
RandStatesimultaneously, since this involves an update of the object. - the function
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classRandState.RandomStateCleanerCleaning action for theRandStateclass.
-
Field Summary
Fields Modifier and Type Field Description private GmpRandstateTrandstateNativeThe pointer to the nativegmp_randstate_tobject.
-
Constructor Summary
Constructors Modifier Constructor Description RandState()Builds the default random state.privateRandState(GmpRandstateT pointer)A private constructor which build aRandStatestarting 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 GmpRandstateTgetNative()Returns the native pointer to the GMP object.static RandStaterandinitDefault()Returns 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 RandStaterandinitMt()Returns a random state for a Mersenne Twister algorithm.RandStaterandinitSet(RandState op)Returns a random state which is a copy ofop.RandStaterandseed(MPZ seed)Sets an initial seed value into this.RandStaterandseedUi(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 Detail
-
randstateNative
private GmpRandstateT randstateNative
The pointer to the nativegmp_randstate_tobject.
-
-
Constructor Detail
-
RandState
private RandState(GmpRandstateT pointer)
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
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- ifsizeis 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 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.
-
-