Node:Random State Initialization, Next:, Previous:Random Number Functions, Up:Random Number Functions



Random State Initialization

void gmp_randinit_default (gmp_randstate_t state) Function
Initialize state with a default algorithm. This will be a compromise between speed and randomness, and is recommended for applications with no special requirements.

void gmp_randinit_lc_2exp (gmp_randstate_t state, mpz_t a, unsigned long c, unsigned long m2exp) Function
Initialize state with a linear congruential algorithm X = (a*X + c) mod 2^m2exp.

The low bits of X in this algorithm are not very random. The least significant bit will have a period no more than 2, and the second bit no more than 4, etc. For this reason only the high half of each X is actually used.

When a random number of more than m2exp/2 bits is to be generated, multiple iterations of the recurrence are used and the results concatenated.

int gmp_randinit_lc_2exp_size (gmp_randstate_t state, unsigned long size) Function
Initialize state for a linear congruential algorithm as per gmp_randinit_lc_2exp. a, c and m2exp are selected from a table, chosen so that size bits (or more) of each X will be used, ie. m2exp >= size/2.

If successful the return value is non-zero. If size is bigger than the table data provides then the return value is zero. The maximum size currently supported is 128.

void gmp_randinit (gmp_randstate_t state, gmp_randalg_t alg, ...) Function
This function is obsolete.

Initialize state with an algorithm selected by alg. The only choice is GMP_RAND_ALG_LC, which is gmp_randinit_lc_2exp_size. A third parameter of type unsigned long is required, this is the size for that function. GMP_RAND_ALG_DEFAULT or 0 are the same as GMP_RAND_ALG_LC.

gmp_randinit sets bits in gmp_errno to indicate an error. GMP_ERROR_UNSUPPORTED_ARGUMENT if alg is unsupported, or GMP_ERROR_INVALID_ARGUMENT if the size parameter is too big.

void gmp_randclear (gmp_randstate_t state) Function
Free all memory occupied by state.