xref: /netbsd-src/external/lgpl3/gmp/dist/tests/rand/t-iset.c (revision 19ef5b5b0bcb90f63509df6e78769de1b57c2758)
1 /* Test gmp_randinit_set.
2 
3 Copyright 2003 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 http://www.gnu.org/licenses/.  */
19 
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include "gmp.h"
23 #include "gmp-impl.h"
24 #include "tests.h"
25 
26 /* expect after a gmp_randinit_set that the new and old generators will
27    produce the same sequence of numbers */
28 void
29 check_one (const char *name, gmp_randstate_ptr src)
30 {
31   gmp_randstate_t dst;
32   mpz_t  sz, dz;
33   int    i;
34 
35   gmp_randinit_set (dst, src);
36   mpz_init (sz);
37   mpz_init (dz);
38 
39   for (i = 0; i < 20; i++)
40     {
41       mpz_urandomb (sz, src, 123);
42       mpz_urandomb (dz, dst, 123);
43 
44       if (mpz_cmp (sz, dz) != 0)
45         {
46           printf     ("gmp_randinit_set didn't duplicate randstate\n");
47           printf     ("  algorithm: %s\n", name);
48           gmp_printf ("  from src:  %#Zx\n", sz);
49           gmp_printf ("  from dst:  %#Zx\n", dz);
50           abort ();
51         }
52     }
53 
54   mpz_clear (sz);
55   mpz_clear (dz);
56   gmp_randclear (dst);
57 }
58 
59 int
60 main (int argc, char *argv[])
61 {
62   tests_start ();
63 
64   call_rand_algs (check_one);
65 
66   tests_end ();
67   exit (0);
68 }
69