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