summaryrefslogtreecommitdiff
path: root/random.c
diff options
context:
space:
mode:
Diffstat (limited to 'random.c')
-rw-r--r--random.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/random.c b/random.c
index f596accf5..1f2229b62 100644
--- a/random.c
+++ b/random.c
@@ -24,44 +24,44 @@ MA 02111-1307, USA. */
#include "mpfr.h"
#include "gmp-impl.h"
#include "longlong.h"
-#include "urandom.h"
-#include "srandom.h"
/* Computes a random mpfr in [0, 1[ with precision MPFR_PREC */
void
#if __STDC__
-mpfr_random(mpfr_ptr x)
+mpfr_random (mpfr_ptr x)
#else
-mpfr_random(x)
+mpfr_random (x)
mpfr_ptr x;
#endif
{
- mp_limb_t *xp; unsigned long xn, i, cnt, prec=MPFR_PREC(x);
+ mp_limb_t *xp; unsigned long xn, cnt, prec = MPFR_PREC(x);
MPFR_CLEAR_FLAGS(x);
xp = MPFR_MANT(x);
xn = (prec-1)/BITS_PER_MP_LIMB + 1;
- for (i = 0; i < xn; i++)
- xp[i] = urandom();
-
- count_leading_zeros(cnt, xp[xn - 1]);
- if (cnt) mpn_lshift(xp, xp, xn, cnt);
+ mpn_random (xp, xn);
+
+ if (xp[xn - 1] == 0) xp[xn - 1] = 1;
+ /* since count_leading_zeros doesn't like zeroes */
+
+ count_leading_zeros (cnt, xp[xn - 1]);
+ if (cnt) mpn_lshift (xp, xp, xn, cnt);
MPFR_EXP(x) = -cnt;
cnt = xn*BITS_PER_MP_LIMB - prec;
/* cnt is the number of non significant bits in the low limb */
- xp[0] &= ~((((mp_limb_t)1)<<cnt) - 1);
+ xp[0] &= ~((((mp_limb_t) 1) << cnt) - 1);
}
void
#if __STDC__
-mpfr_srandom(unsigned long int seed)
+mpfr_srandom (unsigned long int seed)
#else
-mpfr_srandom(seed)
+mpfr_srandom (seed)
unsigned long int seed;
#endif
{
- srandom(seed);
+ srandom (seed);
}