diff options
author | tege <tege@gmplib.org> | 2004-12-04 05:59:42 +0100 |
---|---|---|
committer | tege <tege@gmplib.org> | 2004-12-04 05:59:42 +0100 |
commit | a32da81e66e20d852ecc3f4302f50b576aef1676 (patch) | |
tree | 62f9a51d17a9ac13ef6dc28973d501b0d3b01541 /mpz/rrandomb.c | |
parent | ddaaea90ee6994d866acfce95f18db4e44bb1001 (diff) | |
download | gmp-a32da81e66e20d852ecc3f4302f50b576aef1676.tar.gz |
(gmp_rrandomb): Rework again.
Diffstat (limited to 'mpz/rrandomb.c')
-rw-r--r-- | mpz/rrandomb.c | 10 |
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; } } |