summaryrefslogtreecommitdiff
path: root/mpz
diff options
context:
space:
mode:
authorMarco Bodrato <bodrato@mail.dm.unipi.it>2013-02-12 15:41:57 +0100
committerMarco Bodrato <bodrato@mail.dm.unipi.it>2013-02-12 15:41:57 +0100
commitf60380ebc78b92d696929cd7da6f7c810d52f21d (patch)
tree37766edbcf0308ae9cb7591bbd1d8d8b5d453123 /mpz
parenta48fddf29870af5f7d62efebafc26697a0e1b09e (diff)
downloadgmp-f60380ebc78b92d696929cd7da6f7c810d52f21d.tar.gz
Use BITS_TO_LIMBS and MPZ_NEWALLOC in random functions.
Diffstat (limited to 'mpz')
-rw-r--r--mpz/rrandomb.c6
-rw-r--r--mpz/urandomb.c2
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);