summaryrefslogtreecommitdiff
path: root/mpz/rrandomb.c
diff options
context:
space:
mode:
authortege <tege@gmplib.org>2004-12-04 05:59:42 +0100
committertege <tege@gmplib.org>2004-12-04 05:59:42 +0100
commita32da81e66e20d852ecc3f4302f50b576aef1676 (patch)
tree62f9a51d17a9ac13ef6dc28973d501b0d3b01541 /mpz/rrandomb.c
parentddaaea90ee6994d866acfce95f18db4e44bb1001 (diff)
downloadgmp-a32da81e66e20d852ecc3f4302f50b576aef1676.tar.gz
(gmp_rrandomb): Rework again.
Diffstat (limited to 'mpz/rrandomb.c')
-rw-r--r--mpz/rrandomb.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/mpz/rrandomb.c b/mpz/rrandomb.c
index eccd45980..b8bba8cb5 100644
--- a/mpz/rrandomb.c
+++ b/mpz/rrandomb.c
@@ -68,10 +68,14 @@ gmp_rrandomb (mp_ptr rp, gmp_randstate_t rstate, unsigned long int nbits)
cap_chunksize = nbits / (ranm % 4 + 1);
cap_chunksize += cap_chunksize == 0; /* make it at least 1 */
- bi = nbits - 1;
+ bi = nbits;
for (;;)
{
+ _gmp_rand (&ranm, rstate, BITS_PER_RANDCALL);
+ chunksize = 1 + ranm % cap_chunksize;
+ bi = (bi < chunksize) ? 0 : bi - chunksize;
+
if (bi == 0)
break; /* low chunk is ...1 */
@@ -85,9 +89,5 @@ gmp_rrandomb (mp_ptr rp, gmp_randstate_t rstate, unsigned long int nbits)
if (bi == 0)
break; /* low chunk is ...0 */
-
- _gmp_rand (&ranm, rstate, BITS_PER_RANDCALL);
- chunksize = 1 + ranm % cap_chunksize;
- bi = (bi < chunksize) ? 0 : bi - chunksize;
}
}