1 /* Exercise the lc2exp random functions.
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/. */
27 /* a=0 and c=0 produces zero results always. */
29 check_zero (unsigned long m2exp)
36 mpz_init_set_ui (a, 0L);
39 gmp_randinit_lc_2exp (r, a, c, m2exp);
40 gmp_randseed_ui (r, 0L);
42 for (i = 0; i < 5; i++)
44 mpz_urandomb (a, r, 123L);
47 printf ("check_zero m2exp=%lu: didn't get zero\n", m2exp);
48 gmp_printf (" rand=%#Zx\n", a);
63 unsigned long c, m2exp;
67 mpz_setbit (a, 1000L);
72 gmp_randinit_lc_2exp (r, a, c, m2exp);
73 gmp_randseed_ui (r, 0L);
75 for (i = 0; i < 5; i++)
77 mpz_urandomb (a, r, 123L);
79 printf ("check_nega m2exp=%lu: didn't get zero\n", m2exp);
91 unsigned long c, m2exp, bits;
94 mpz_init_set_ui (a, 0L);
98 gmp_randinit_lc_2exp (r, a, c, m2exp);
99 gmp_randseed_ui (r, 0L);
101 for (i = 0; i < 20; i++)
104 mpz_urandomb (a, r, bits);
105 if (mpz_sgn (a) < 0 || mpz_sizeinbase (a, 2) > bits)
107 printf ("check_bigc: mpz_urandomb out of range\n");
108 printf (" m2exp=%lu\n", m2exp);
109 gmp_printf (" rand=%#ZX\n", a);
110 gmp_printf (" sizeinbase2=%u\n", mpz_sizeinbase (a, 2));
123 unsigned long c, m2exp;
126 mpz_init_set_ui (a, 0L);
130 gmp_randinit_lc_2exp (r, a, c, m2exp);
131 gmp_randseed_ui (r, 0L);
133 for (i = 0; i < 20; i++)
135 mpz_urandomb (a, r, 1L);
136 if (mpz_cmp_ui (a, 1L) != 0)
138 printf ("check_bigc1: mpz_urandomb didn't give 1\n");
139 printf (" m2exp=%lu\n", m2exp);
140 gmp_printf (" got rand=%#ZX\n", a);
149 /* Checks parameters which triggered an assertion failure in the past.
150 Happened when limbs(a)+limbs(c) < bits_to_limbs(m2exp). */
154 gmp_randstate_t rstate;
157 mpz_init_set_ui (a, 5L);
158 gmp_randinit_lc_2exp (rstate, a, 1L, 384L);
160 mpz_urandomb (a, rstate, 20L);
162 gmp_randclear (rstate);
166 /* Checks for seeds bigger than the modulus. */
170 gmp_randstate_t rstate;
175 mpz_setbit (sd, 300L);
176 mpz_sub_ui (sd, sd, 1L);
177 mpz_clrbit (sd, 13L);
178 mpz_init_set_ui (a, 123456789L);
180 gmp_randinit_lc_2exp (rstate, a, 5L, 64L);
182 for (i = 0; i < 20; i++)
185 gmp_randseed (rstate, sd);
186 mpz_mul_ui (sd, sd, 7L);
188 mpz_urandomb (a, rstate, 80L);
191 gmp_randclear (rstate);