void mpz_rrandomb (mpz_ptr x, gmp_randstate_t rstate, mp_bitcnt_t nbits) { mp_size_t nl; nl = (nbits + GMP_NUMB_BITS - 1) / GMP_NUMB_BITS; if (nbits != 0) { MPZ_REALLOC (x, nl); gmp_rrandomb (PTR(x), rstate, nbits); } SIZ(x) = nl; }
void mpz_rrandomb (mpz_ptr x, gmp_randstate_t rstate, mp_bitcnt_t nbits) { mp_size_t nl; mp_ptr xp; nl = BITS_TO_LIMBS (nbits); if (nbits != 0) { xp = MPZ_NEWALLOC (x, nl); gmp_rrandomb (xp, rstate, nbits); } SIZ(x) = nl; }
void mpn_rrandom (mp_ptr rp, gmp_randstate_t rnd, mp_size_t n) { int bit_pos; /* bit number of least significant bit where next bit field to be inserted */ mp_limb_t ran, ranm; /* buffer for random bits */ /* FIXME: Is n==0 supposed to be allowed? */ ASSERT (n >= 0); _gmp_rand (&ranm, rnd, BITS_PER_RANDCALL); ran = ranm; /* Start off at a random bit position in the most significant limb. */ bit_pos = ran % GMP_NUMB_BITS; gmp_rrandomb (rp, rnd, n * GMP_NUMB_BITS - bit_pos); }