diff options
author | hanrot <hanrot@280ebfd0-de03-0410-8827-d642c229c3f4> | 1999-06-15 12:06:32 +0000 |
---|---|---|
committer | hanrot <hanrot@280ebfd0-de03-0410-8827-d642c229c3f4> | 1999-06-15 12:06:32 +0000 |
commit | d812ff11d60968878a1077b89d0908b65cf480d2 (patch) | |
tree | f111b88df5bfccadf220e05582f76e562e24b87e /random.c | |
parent | 6ed5aacdef808675df61c7af3f17b796518db1a2 (diff) | |
download | mpfr-d812ff11d60968878a1077b89d0908b65cf480d2.tar.gz |
Correction de bug (pas msb normalise).
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@46 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'random.c')
-rw-r--r-- | random.c | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -1,6 +1,7 @@ #include <stdio.h> #include "gmp.h" #include "gmp-impl.h" +#include "longlong.h" #include "mpfr.h" /* Computes a random mpfr in [0, 1[ with precision PREC */ @@ -8,22 +9,24 @@ void mpfr_random(mpfr_ptr x) { - mp_limb_t *xp; unsigned long xs, i; + mp_limb_t *xp; unsigned long xs, i, cnt; - EXP(x) = 0; xp = MANT(x); xs = ABSSIZE(x); for (i = 0; i < xs; i++) { - /* random() could be replaced by a homemade random number generator. + /* random() c/sh/ould be replaced by a homemade random number generator. Indeed, if on Linux random is a good RNG, this is definitely not the case in most Un*xes. */ xp[i] = random(); } + count_leading_zeros(cnt, xp[xs - 1]); + if (cnt) mpn_lshift(xp, xp, xs, cnt); + EXP(x) = -cnt; mpfr_round_raw(xp, xp, random()&3, SIZE(x), PREC(x)); - /* Since the value 1 is forbidden, ignore any possible carry. */ + /* ignore any possible carry (this is sheer laziness). */ } void |