Package it.unich.jgmp

Class RandState

java.lang.Object
it.unich.jgmp.RandState

public class RandState extends Object
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 the RandState class;
  • if the function name begins with gmp_randinit, we create a static method caleed baseName which returns a new RandState object;
  • otherwise, we create a method baseName which calls the original function, implicitly using this as the first non-constant gmp_randstate_t parameter.
Other methods and constructors which conform to standard Java naming conventions might be provided.

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.

  • Field Details

    • randstateNative

      private GmpRandstateT randstateNative
      The pointer to the native gmp_randstate_t object.
  • Constructor Details

    • RandState

      private RandState(GmpRandstateT pointer)
      A private constructor which build a RandState 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 Details

    • 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 function gmp_randinit_lc_2exp.
    • randinitLc2ExpSize

      public static RandState randinitLc2ExpSize(long size)
      Returns a random state for a linear congruential algorithm. See the GMP function gmp_randinit_lc_2exp_size.
      Throws:
      IllegalArgumentException - if size is too big.
    • randinitSet

      public RandState randinitSet(RandState op)
      Returns a random state which is a copy of op.
    • randseed

      public RandState randseed(MPZ seed)
      Sets an initial seed value into this.
    • 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 of n bits, in the range 0 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 range 0 to (n - 1) inclusive.