1 /* Test the Mersenne Twister random number generator. 2 3 Copyright 2002 Free Software Foundation, Inc. 4 5 This file is part of the GNU MP Library test suite. 6 7 The GNU MP Library test suite is free software; you can redistribute it 8 and/or modify it under the terms of the GNU General Public License as 9 published by the Free Software Foundation; either version 3 of the License, 10 or (at your option) any later version. 11 12 The GNU MP Library test suite is distributed in the hope that it will be 13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 15 Public License for more details. 16 17 You should have received a copy of the GNU General Public License along with 18 the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ 19 20 #include <stdio.h> 21 #include "gmp-impl.h" 22 #include "tests.h" 23 24 #ifndef TRUE 25 #define TRUE (1) 26 #endif 27 #ifndef FALSE 28 #define FALSE (0) 29 #endif 30 31 /* Test that the sequence without seeding equals the sequence with the 32 default seed. */ 33 int 34 chk_default_seed (void) 35 { 36 gmp_randstate_t r1, r2; 37 mpz_t a, b; 38 int i; 39 int ok = TRUE; 40 41 mpz_init2 (a, 19936L); 42 mpz_init2 (b, 19936L); 43 44 gmp_randinit_mt (r1); 45 gmp_randinit_mt (r2); 46 gmp_randseed_ui (r2, 5489L); /* Must match DEFAULT_SEED in randmt.c */ 47 for (i = 0; i < 3; i++) 48 { 49 /* Extract one whole buffer per iteration. */ 50 mpz_urandomb (a, r1, 19936L); 51 mpz_urandomb (b, r2, 19936L); 52 if (mpz_cmp (a, b) != 0) 53 { 54 ok = FALSE; 55 printf ("Default seed fails in iteration %d\n", i); 56 break; 57 } 58 } 59 gmp_randclear (r1); 60 gmp_randclear (r2); 61 62 mpz_clear (a); 63 mpz_clear (b); 64 return ok; 65 } 66 67 int 68 main (int argc, char *argv[]) 69 { 70 int ok; 71 72 tests_start (); 73 74 ok = chk_default_seed (); 75 76 tests_end (); 77 78 if (ok) 79 return 0; /* pass */ 80 else 81 return 1; /* fail */ 82 } 83