1/* Test the Mersenne Twister random number generator.
2
3Copyright 2002 Free Software Foundation, Inc.
4
5This file is part of the GNU MP Library test suite.
6
7The GNU MP Library test suite is free software; you can redistribute it
8and/or modify it under the terms of the GNU General Public License as
9published by the Free Software Foundation; either version 3 of the License,
10or (at your option) any later version.
11
12The GNU MP Library test suite is distributed in the hope that it will be
13useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
15Public License for more details.
16
17You should have received a copy of the GNU General Public License along with
18the 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.  */
33int
34chk_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
67int
68main (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