Next: C++ Interface Limitations, Previous: C++ Interface Floats, Up: C++ Class Interface [Index]
The C++ class interface to the GMP random number functions uses
gmp_randclass
to hold an algorithm selection and current state, as per
gmp_randstate_t
.
Construct a gmp_randclass
, using a call to the given randinit
function (see Random State Initialization). The arguments expected are
the same as randinit, but with mpz_class
instead of mpz_t
.
For example,
gmp_randclass r1 (gmp_randinit_default); gmp_randclass r2 (gmp_randinit_lc_2exp_size, 32); gmp_randclass r3 (gmp_randinit_lc_2exp, a, c, m2exp); gmp_randclass r4 (gmp_randinit_mt);
gmp_randinit_lc_2exp_size
will fail if the size requested is too big,
an std::length_error
exception is thrown in that case.
Construct a gmp_randclass
using the same parameters as
gmp_randinit
(see Random State Initialization). This function is
obsolete and the above randinit style should be preferred.
Seed a random number generator. See see Random Number Functions, for how to choose a good seed.
Generate a random integer with a specified number of bits.
Generate a random integer in the range 0 to n-1 inclusive.
Generate a random float f in the range 0 <= f < 1. f will be to prec bits precision, or if prec is not given then to the precision of the destination. For example,
gmp_randclass r; ... mpf_class f (0, 512); // 512 bits precision f = r.get_f(); // random number, 512 bits
Next: C++ Interface Limitations, Previous: C++ Interface Floats, Up: C++ Class Interface [Index]