1/* Test gmp_randinit_set. 2 3Copyright 2003 Free Software Foundation, Inc. 4 5This file is part of the GNU MP Library. 6 7The GNU MP Library is free software; you can redistribute it and/or modify 8it under the terms of the GNU Lesser General Public License as published by 9the Free Software Foundation; either version 3 of the License, or (at your 10option) any later version. 11 12The GNU MP Library is distributed in the hope that it will be useful, but 13WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15License for more details. 16 17You should have received a copy of the GNU Lesser General Public License 18along with the GNU MP Library. 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 */ 28void 29check_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 59int 60main (int argc, char *argv[]) 61{ 62 tests_start (); 63 64 call_rand_algs (check_one); 65 66 tests_end (); 67 exit (0); 68} 69