summaryrefslogtreecommitdiff
path: root/random.c
diff options
context:
space:
mode:
authorzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2000-12-15 16:54:50 +0000
committerzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2000-12-15 16:54:50 +0000
commit22dabc2429a6720a548a4d30990c6b53f43154e3 (patch)
tree53c39ca49aeea3db58b6ea337b0582283ba16471 /random.c
parent6378aa07aa0308d2ae51e3929bbd2615731f01fa (diff)
downloadmpfr-22dabc2429a6720a548a4d30990c6b53f43154e3.tar.gz
now uses directly mpn_random, to avoid all problems with include files
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@882 280ebfd0-de03-0410-8827-d642c229c3f4
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);
}