Next: , Previous: , Up: Integer Functions   [Index]


5.13 Random Number Functions

The random number functions of MPIR come in two groups; older function that rely on a global state, and newer functions that accept a state parameter that is read and modified. Please see the Random Number Functions for more information on how to use and not to use random number functions.

Function: void mpz_urandomb (mpz_t rop, gmp_randstate_t state, mp_bitcnt_t n)

Generate a uniformly distributed random integer in the range 0 to 2^n-1, inclusive.

The variable state must be initialized by calling one of the gmp_randinit functions (Random State Initialization) before invoking this function.

Function: void mpz_urandomm (mpz_t rop, gmp_randstate_t state, mpz_t n)

Generate a uniform random integer in the range 0 to n-1, inclusive.

The variable state must be initialized by calling one of the gmp_randinit functions (Random State Initialization) before invoking this function.

Function: void mpz_rrandomb (mpz_t rop, gmp_randstate_t state, mp_bitcnt_t n)

Generate a random integer with long strings of zeros and ones in the binary representation. Useful for testing functions and algorithms, since this kind of random numbers have proven to be more likely to trigger corner-case bugs. The random number will be in the range 0 to 2^n-1, inclusive.

The variable state must be initialized by calling one of the gmp_randinit functions (Random State Initialization) before invoking this function.