diff options
Diffstat (limited to 'tests/random.c')
-rw-r--r-- | tests/random.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/random.c b/tests/random.c index 5fb7adf..0420f66 100644 --- a/tests/random.c +++ b/tests/random.c @@ -159,6 +159,35 @@ test_default_random (mpc_ptr z, mpfr_exp_t emin, mpfr_exp_t emax, mpfr_neg (mpc_imagref (z), mpc_imagref (z), MPFR_RNDN); } +/* Set n to a non zero value random value with absolute values less than + 2^emax. + + n is negative with probability equal to NEGATIVE_PROBABILITY / 256. +*/ +void test_random_si (long int *n, unsigned long emax, + unsigned int negative_probability) +{ + unsigned long r; + + if (!rands_initialized) + { + fprintf (stderr, + "Put test_start at the beginning of your test function.\n"); + exit (1); + } + + do + { + *n = gmp_urandomb_ui (rands, emax); + } while (*n == 0); + + if (negative_probability > 256) + negative_probability = 256; + r = gmp_urandomb_ui (rands, 8); + if ((r & 0xFF) < negative_probability) + *n = -(*n); +} + /* Set x to a non zero value random value with absolute values greater than or equal to 2^{emin-1} and less than 2^emax. |