diff options
author | Marco Bodrato <bodrato@mail.dm.unipi.it> | 2013-02-12 15:41:57 +0100 |
---|---|---|
committer | Marco Bodrato <bodrato@mail.dm.unipi.it> | 2013-02-12 15:41:57 +0100 |
commit | f60380ebc78b92d696929cd7da6f7c810d52f21d (patch) | |
tree | 37766edbcf0308ae9cb7591bbd1d8d8b5d453123 /mpz | |
parent | a48fddf29870af5f7d62efebafc26697a0e1b09e (diff) | |
download | gmp-f60380ebc78b92d696929cd7da6f7c810d52f21d.tar.gz |
Use BITS_TO_LIMBS and MPZ_NEWALLOC in random functions.
Diffstat (limited to 'mpz')
-rw-r--r-- | mpz/rrandomb.c | 6 | ||||
-rw-r--r-- | mpz/urandomb.c | 2 |
2 files changed, 4 insertions, 4 deletions
diff --git a/mpz/rrandomb.c b/mpz/rrandomb.c index 3e06e2c70..739d14cc6 100644 --- a/mpz/rrandomb.c +++ b/mpz/rrandomb.c @@ -30,10 +30,10 @@ mpz_rrandomb (mpz_ptr x, gmp_randstate_t rstate, mp_bitcnt_t nbits) mp_size_t nl; mp_ptr xp; - nl = (nbits + GMP_NUMB_BITS - 1) / GMP_NUMB_BITS; + nl = BITS_TO_LIMBS (nbits); if (nbits != 0) { - xp = MPZ_REALLOC (x, nl); + xp = MPZ_NEWALLOC (x, nl); gmp_rrandomb (xp, rstate, nbits); } @@ -58,7 +58,7 @@ gmp_rrandomb (mp_ptr rp, gmp_randstate_t rstate, mp_bitcnt_t nbits) mp_size_t i; /* Set entire result to 111..1 */ - i = (nbits + GMP_NUMB_BITS - 1) / GMP_NUMB_BITS - 1; + i = BITS_TO_LIMBS (nbits) - 1; rp[i] = GMP_NUMB_MAX >> (GMP_NUMB_BITS - (nbits % GMP_NUMB_BITS)) % GMP_NUMB_BITS; for (i = i - 1; i >= 0; i--) rp[i] = GMP_NUMB_MAX; diff --git a/mpz/urandomb.c b/mpz/urandomb.c index fc7ec55ce..00b6f2ed8 100644 --- a/mpz/urandomb.c +++ b/mpz/urandomb.c @@ -29,7 +29,7 @@ mpz_urandomb (mpz_ptr rop, gmp_randstate_t rstate, mp_bitcnt_t nbits) mp_size_t size; size = BITS_TO_LIMBS (nbits); - rp = MPZ_REALLOC (rop, size); + rp = MPZ_NEWALLOC (rop, size); _gmp_rand (rp, rstate, nbits); MPN_NORMALIZE (rp, size); |