Austin Schuh | dace2a6 | 2020-08-18 10:56:48 -0700 | [diff] [blame] | 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 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 */ |
| 27 | void |
| 28 | check_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 | |
| 58 | int |
| 59 | main (int argc, char *argv[]) |
| 60 | { |
| 61 | tests_start (); |
| 62 | |
| 63 | call_rand_algs (check_one); |
| 64 | |
| 65 | tests_end (); |
| 66 | exit (0); |
| 67 | } |