From 36dfe3df4c7aa2a8973056e5feec4d25349101f4 Mon Sep 17 00:00:00 2001 From: tege Date: Wed, 3 Jan 2001 18:25:42 +0100 Subject: Generate test operands using new random functions. --- mpz/tests/io.c | 42 +++++++++++++++++++++++++++++++++--------- mpz/tests/logic.c | 52 +++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 72 insertions(+), 22 deletions(-) (limited to 'mpz') diff --git a/mpz/tests/io.c b/mpz/tests/io.c index e4e4f6e1d..134eecf67 100644 --- a/mpz/tests/io.c +++ b/mpz/tests/io.c @@ -30,14 +30,9 @@ MA 02111-1307, USA. */ #include "gmp.h" #include "gmp-impl.h" -#include "urandom.h" #define FILENAME "io.tmp" -#ifndef SIZE -#define SIZE 16 -#endif - void debug_mp (mpz_t x, int base) { @@ -53,6 +48,25 @@ main (int argc, char **argv) int reps = 10000; FILE *fp; int base; + gmp_randstate_t rands; + mpz_t bs; + unsigned long bsi, size_range; + char *perform_seed; + + gmp_randinit (rands, GMP_RAND_ALG_LC, 64); + + perform_seed = getenv ("GMP_CHECK_RANDOMIZE"); + if (perform_seed != 0) + { + struct timeval tv; + gettimeofday (&tv, NULL); + gmp_randseed_ui (rands, tv.tv_sec + tv.tv_usec); + printf ("PLEASE INCLUDE THIS SEED NUMBER IN ALL BUG REPORTS:\n"); + printf ("GMP_CHECK_RANDOMIZE is set--seeding with %ld\n", + tv.tv_sec + tv.tv_usec); + } + + mpz_init (bs); if (argc == 2) reps = atoi (argv[1]); @@ -64,10 +78,20 @@ main (int argc, char **argv) for (i = 0; i < reps; i++) { - size = urandom () % SIZE - SIZE/2; - - mpz_random2 (op1, size); - base = urandom () % 36 + 1; + mpz_urandomb (bs, rands, 32); + size_range = mpz_get_ui (bs) % 10 + 2; + + mpz_urandomb (bs, rands, size_range); + size = mpz_get_ui (bs); + mpz_rrandomb (op1, rands, size); + mpz_urandomb (bs, rands, 1); + bsi = mpz_get_ui (bs); + if ((bsi & 1) != 0) + mpz_neg (op1, op1); + + mpz_urandomb (bs, rands, 16); + bsi = mpz_get_ui (bs); + base = bsi % 36 + 1; if (base == 1) base = 0; diff --git a/mpz/tests/logic.c b/mpz/tests/logic.c index cfee3451f..3b8cc324d 100644 --- a/mpz/tests/logic.c +++ b/mpz/tests/logic.c @@ -25,22 +25,36 @@ MA 02111-1307, USA. */ #include "gmp.h" #include "gmp-impl.h" -#include "urandom.h" void dump_abort _PROTO (()); void debug_mp _PROTO ((mpz_t, int)); -#ifndef SIZE -#define SIZE 16 -#endif - main (int argc, char **argv) { mpz_t x, y, r1, r2; - mpz_t t1, t2, t3, t4; + mpz_t t1, t2, t3; mp_size_t xsize, ysize; int i; - int reps = 100000; + int reps = 40000; + gmp_randstate_t rands; + mpz_t bs; + unsigned long bsi, size_range; + char *perform_seed; + + gmp_randinit (rands, GMP_RAND_ALG_LC, 64); + + perform_seed = getenv ("GMP_CHECK_RANDOMIZE"); + if (perform_seed != 0) + { + struct timeval tv; + gettimeofday (&tv, NULL); + gmp_randseed_ui (rands, tv.tv_sec + tv.tv_usec); + printf ("PLEASE INCLUDE THIS SEED NUMBER IN ALL BUG REPORTS:\n"); + printf ("GMP_CHECK_RANDOMIZE is set--seeding with %ld\n", + tv.tv_sec + tv.tv_usec); + } + + mpz_init (bs); if (argc == 2) reps = atoi (argv[1]); @@ -52,15 +66,27 @@ main (int argc, char **argv) mpz_init (t1); mpz_init (t2); mpz_init (t3); - mpz_init (t4); for (i = 0; i < reps; i++) { - xsize = urandom () % SIZE - SIZE/2; - mpz_random2 (x, xsize); - - ysize = urandom () % SIZE - SIZE/2; - mpz_random2 (y, ysize); + mpz_urandomb (bs, rands, 32); + size_range = mpz_get_ui (bs) % 8 + 2; + + mpz_urandomb (bs, rands, size_range); + xsize = mpz_get_ui (bs); + mpz_rrandomb (x, rands, xsize); + mpz_urandomb (bs, rands, 1); + bsi = mpz_get_ui (bs); + if ((bsi & 1) != 0) + mpz_neg (x, x); + + mpz_urandomb (bs, rands, size_range); + ysize = mpz_get_ui (bs); + mpz_rrandomb (y, rands, ysize); + mpz_urandomb (bs, rands, 1); + bsi = mpz_get_ui (bs); + if ((bsi & 1) != 0) + mpz_neg (y, y); mpz_com (r1, x); MPZ_CHECK_FORMAT (r1); -- cgit v1.2.1