3 Copyright 2002 Free Software Foundation, Inc.
5 This file is part of the GNU MP Library.
7 The GNU MP Library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
12 The GNU MP Library is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
35 gmp_randstate_t r1, r2;
48 /* Test the consistency between urandomm and urandomb. */
49 gmp_randinit_default (r1);
50 gmp_randinit_default (r2);
51 gmp_randseed_ui (r1, 85L);
52 gmp_randseed_ui (r2, 85L);
55 for (i = 0; i < 100; i++)
57 mpz_urandomm (a, r1, m);
58 mpz_urandomb (b, r2, 80L);
59 if (mpz_cmp (a, b) != 0)
62 printf ("mpz_urandomm != mpz_urandomb\n");
72 /* Test that mpz_urandomm returns the correct result with a
75 gmp_randinit_lc_2exp (r1, a, 0xffL, 8L);
77 /* Warning: This code hangs in gmp 4.1 and below */
78 for (i = 0; i < 100; i++)
80 mpz_urandomm (a, r1, m);
81 if (mpz_cmp_ui (a, 2L) != 0)
84 gmp_printf ("mpz_urandomm returns %Zd instead of 2\n", a);
93 /* Test that the results are always in range for either
94 positive or negative values of m. */
95 gmp_randinit_default (r1);
98 for (i = 0; i < 100; i++)
100 mpz_urandomm (a, r1, m);
101 if (mpz_cmp_ui (a, 5L) >= 0 || mpz_sgn (a) < 0)
104 gmp_printf ("Out-of-range or non-positive value: %Zd\n", a);
107 mpz_urandomm (a, r1, b);
108 if (mpz_cmp_ui (a, 5L) >= 0 || mpz_sgn (a) < 0)
111 gmp_printf ("Out-of-range or non-positive value (from negative modulus): %Zd\n", a);
120 /* Test that m=1 forces always result=0. */
121 gmp_randinit_default (r1);
123 for (i = 0; i < 100; i++)
125 mpz_urandomm (a, r1, m);
126 if (mpz_sgn (a) != 0)
129 gmp_printf ("mpz_urandomm fails with m=1 (result=%Zd)\n", a);
143 main (int argc, char *argv[])
150 if (!check_params ())