Package gmp

Class RandState

java.lang.Object
gmp.RandState

public class RandState extends Object
Pseudo-random number generation states.

A RandState object wraps a gmp_randstate_t GMP object, i.e., a state for pseudo-random number generation functions. The state defines an algorithm and a current value state (that should be seeded).

  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a random state with the default algorithm.
    RandState(boolean b)
    Creates a random state for a Mersenne Twister algorithm.
    RandState(int size)
    Creates a random state for a congruential algorithm.
    RandState(Mpz a, int c, int m2exp)
    Creates a random state for a congruential algorithm.
    Creates a copy of the random state op.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    randomBits(int n)
    Returns an uniformly distributed random number of n bits (i.e., in 0..2^n-1).
    int
    randomInt(int n)
    Returns an uniformly distributed random number in 0..n-1.
    void
    Seed(int seed)
    Sets an initial seed value for the state.
    void
    Seed(Mpz seed)
    Sets an initial seed value for the state.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • RandState

      public RandState()
      Creates a random state with the default algorithm.
    • RandState

      public RandState(boolean b)
      Creates a random state for a Mersenne Twister algorithm.

      The boolean argument is not actually used. It is used to differentiate from the default algorithm constructor.

    • RandState

      public RandState(Mpz a, int c, int m2exp)
      Creates a random state for a congruential algorithm.

      X=(aX+c) mod 2^m2exp.

    • RandState

      public RandState(int size)
      Creates a random state for a congruential algorithm.

      The multiplicand and modulo are selected from a table to ensure that at least size bits of each value is used.

      The maximum size currently supported is 128.

    • RandState

      public RandState(RandState op)
      Creates a copy of the random state op.
  • Method Details

    • Seed

      public void Seed(Mpz seed)
      Sets an initial seed value for the state.
    • Seed

      public void Seed(int seed)
      Sets an initial seed value for the state.
    • randomBits

      public int randomBits(int n)
      Returns an uniformly distributed random number of n bits (i.e., in 0..2^n-1).

      n must be positive.

    • randomInt

      public int randomInt(int n)
      Returns an uniformly distributed random number in 0..n-1.

      n must be positive.