DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK

# (gmp.info.gz) Random State Initialization

Info Catalog (gmp.info.gz) Random Number Functions (gmp.info.gz) Random Number Functions (gmp.info.gz) Random State Seeding
```
Random State Initialization
===========================

- Function: void gmp_randinit_default (gmp_randstate_t STATE)
Initialize STATE with a default algorithm.  This will be a
compromise between speed and randomness, and is recommended for
applications with no special requirements.  Currently this is
`gmp_randinit_mt'.

- Function: int gmp_randinit_mt (gmp_randstate_t STATE)
Initialize STATE for a Mersenne Twister algorithm.  This algorithm
is fast and has good randomness properties.

- Function: void gmp_randinit_lc_2exp (gmp_randstate_t STATE, mpz_t A,
unsigned long C, unsigned long M2EXP)
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.

- Function: int gmp_randinit_lc_2exp_size (gmp_randstate_t STATE,
unsigned long SIZE)
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/2 >= SIZE.

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.

- Function: int gmp_randinit_set (gmp_randstate_t ROP, gmp_randstate_t
OP)
Initialize ROP with a copy of the algorithm and state from OP.

- Function: void gmp_randinit (gmp_randstate_t STATE,
gmp_randalg_t ALG, ...)
*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'
described above.  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 the global variable `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.  It may be noted this error reporting is not thread
safe (a good reason to use `gmp_randinit_lc_2exp_size' instead).

- Function: void gmp_randclear (gmp_randstate_t STATE)
Free all memory occupied by STATE.

```
Info Catalog (gmp.info.gz) Random Number Functions (gmp.info.gz) Random Number Functions (gmp.info.gz) Random State Seeding
automatically generated byinfo2html