Copyright (C) 2000-2012 |
GNU Info (gmp.info)C++ Interface Random NumbersC++ Interface Random Numbers ============================ - Class: gmp_randclass 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'. - Function: gmp_randclass::gmp_randclass (void (*RANDINIT) (gmp_randstate_t, ...), ...) Construct a `gmp_randclass', using a call to the given RANDINIT function (Note: 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_randinit_lc_2exp_size' can fail if the size requested is too big, the behaviour of `gmp_randclass::gmp_randclass' is undefined in this case (perhaps this will change in the future). - Function: gmp_randclass::gmp_randclass (gmp_randalg_t ALG, ...) Construct a `gmp_randclass' using the same parameters as `gmp_randinit' (Note: Random State Initialization). This function is obsolete and the above RANDINIT style should be preferred. - Function: void gmp_randclass::seed (unsigned long int S) - Function: void gmp_randclass::seed (mpz_class S) Seed a random number generator. See Note: Random Number Functions, for how to choose a good seed. - Function: mpz_class gmp_randclass::get_z_bits (unsigned long BITS) - Function: mpz_class gmp_randclass::get_z_bits (mpz_class BITS) Generate a random integer with a specified number of bits. - Function: mpz_class gmp_randclass::get_z_range (mpz_class N) Generate a random integer in the range 0 to N-1 inclusive. - Function: mpf_class gmp_randclass::get_f () - Function: mpf_class gmp_randclass::get_f (unsigned long PREC) 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 automatically generated by info2www version 1.2.2.9 |