diff options
author | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2010-09-15 02:50:32 +0000 |
---|---|---|
committer | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2010-09-15 02:50:32 +0000 |
commit | 0b23908acd8e0115b2786236df83a0ff558b81ac (patch) | |
tree | 4d3b04f7819f0453e75836135541825d27304d61 /src/urandomb.c | |
parent | 5f7a7b56ea85dc2fda07f6dc6d956400fdc2d597 (diff) | |
download | mpfr-0b23908acd8e0115b2786236df83a0ff558b81ac.tar.gz |
[urandomb.c] modified to leave the GMP random generator in the same state,
independent of GMP_NUMB_BITS
[trandom.c] test of the above
[urandom.c] added FIXME's
[turandom.c] check we leave the GMP random generator in the same state,
independent of GMP_NUMB_BITS. Currently this fails on 64-bit
computers.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@7133 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'src/urandomb.c')
-rw-r--r-- | src/urandomb.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/urandomb.c b/src/urandomb.c index d8eac64ab..1c05d5023 100644 --- a/src/urandomb.c +++ b/src/urandomb.c @@ -54,14 +54,14 @@ mpfr_urandomb (mpfr_ptr rop, gmp_randstate_t rstate) nbits = MPFR_PREC (rop); nlimbs = MPFR_LIMB_SIZE (rop); MPFR_SET_POS (rop); + cnt = nlimbs * GMP_NUMB_BITS - nbits; /* Uniform non-normalized significand */ - mpfr_rand_raw (rp, rstate, nlimbs * GMP_NUMB_BITS); - - /* If nbits isn't a multiple of GMP_NUMB_BITS, mask the low bits */ - cnt = nlimbs * GMP_NUMB_BITS - nbits; - if (MPFR_LIKELY (cnt != 0)) - rp[0] &= ~MPFR_LIMB_MASK (cnt); + /* generate exactly nbits so that the random generator stays in the same + state, independent of the machine word size GMP_NUMB_BITS */ + mpfr_rand_raw (rp, rstate, nbits); + if (MPFR_LIKELY (cnt != 0)) /* this will put the low bits to zero */ + mpn_lshift (rp, rp, nlimbs, cnt); /* Count the null significant limbs and remaining limbs */ exp = 0; |