diff options
-rw-r--r-- | src/urandomb.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/urandomb.c b/src/urandomb.c index e632ca83d..d8eac64ab 100644 --- a/src/urandomb.c +++ b/src/urandomb.c @@ -27,15 +27,17 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., #define MPFR_NEED_LONGLONG_H #include "mpfr-impl.h" +/* generate nbits random bits into mp[], assuming mp was allocated to contain + a sufficient number of limbs */ void mpfr_rand_raw (mp_ptr mp, gmp_randstate_t rstate, unsigned long int nbits) { mpz_t z; /* To be sure to avoid the potential allocation of mpz_urandomb */ - ALLOC(z) = SIZ(z) = (nbits / GMP_NUMB_BITS) + 1; + ALLOC(z) = SIZ(z) = ((nbits - 1) / GMP_NUMB_BITS) + 1; PTR(z) = mp; - mpz_urandomb(z, rstate, nbits); + mpz_urandomb (z, rstate, nbits); } int |