diff options
author | Linus Nordberg <linus@nordberg.se> | 2000-04-10 13:17:31 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordberg.se> | 2000-04-10 13:17:31 +0200 |
commit | ca6be053cd0d759ef5a8cff53f78f749fe4330b7 (patch) | |
tree | 2a2ef490a831ad8ba80abf49ac522034691a6578 /rand.c | |
parent | 6610cbc458ba35599bc8d1f18df001ea409d3f1f (diff) | |
download | gmp-ca6be053cd0d759ef5a8cff53f78f749fe4330b7.tar.gz |
Rename most of the random number functions, structs and some of the struct members.
Diffstat (limited to 'rand.c')
-rw-r--r-- | rand.c | 61 |
1 files changed, 29 insertions, 32 deletions
@@ -1,4 +1,4 @@ -/* gmp_rand_init (state, size, alg) -- Initialize a random state. +/* gmp_randinit (state, size, alg) -- Initialize a random state. Copyright (C) 1999, 2000 Free Software Foundation, Inc. @@ -25,24 +25,21 @@ MA 02111-1307, USA. */ /* Array of CL-schemes, ordered in increasing order of the first member (the 'm2exp' value). The end of the array is indicated with an entry containing all zeros. */ -static __gmp_rand_lc_scheme_struct __gmp_rand_scheme[] = -{ -#if 0 - /* FIXME: Remove. */ - {8, "7", 0}, /* Test. */ - {31, /* fbsd rand(3) */ - "1103515245", /* a (multiplier) */ - 12345}, /* c (adder) */ -#endif - /* {31, "22298549", 1}, */ - /* merit >= 1; no merit > 3 up to 32845469 */ +/* All multipliers are in the range 0.01*m and 0.99*m, and are +congruent to 5 (mod 8). +They all pass the spectral test with Vt >= 2^(30/t) and merit >= 1. +(Up to and including 196 bits, merit is >= 3.) */ - /* The following multipliers are all between 0.01m and 0.99m, and - are congruent to 5 (mod 8). They all pass the spectral test with - Vt >= 2^(30/t) and merit >= 1. (Up to and including 196 bits, - merit >= 3.) */ +struct __gmp_rand_lc_scheme_struct +{ + unsigned long int m2exp; /* Modulus is 2 ^ m2exp. */ + char *astr; /* Multiplier in string form. */ + unsigned long int c; /* Adder. */ +}; +struct __gmp_rand_lc_scheme_struct __gmp_rand_lc_scheme[] = +{ {32, "43840821", 1}, {33, "85943917", 1}, {34, "171799469", 1}, @@ -65,26 +62,26 @@ static __gmp_rand_lc_scheme_struct __gmp_rand_scheme[] = void #if __STDC__ -gmp_rand_init (gmp_rand_state s, - unsigned long int size, - gmp_rand_algorithm alg) +gmp_randinit (gmp_randstate_t rstate, + unsigned long int size, + gmp_randalg_t alg) #else -gmp_rand_init (s, size, alg) - gmp_rand_state s; +gmp_randinit (rstate, size, alg) + gmp_randstate_t rstate; unsigned long int size; - gmp_rand_algorithm alg; + gmp_randalg_t alg; #endif { switch (alg) { case GMP_RAND_ALG_LC: /* Linear congruential. */ { - __gmp_rand_lc_scheme_struct *sp; + struct __gmp_rand_lc_scheme_struct *sp; mpz_t a; /* Pick a scheme. */ - for (sp = __gmp_rand_scheme; sp->m2exp != 0; sp++) + for (sp = __gmp_rand_lc_scheme; sp->m2exp != 0; sp++) if (sp->m2exp / 2 >= size) break; @@ -96,7 +93,7 @@ gmp_rand_init (s, size, alg) /* Install scheme. */ mpz_init_set_str (a, sp->astr, 0); - gmp_rand_init_lc_2exp (s, a, sp->c, sp->m2exp); + gmp_randinit_lc_2exp (rstate, a, sp->c, sp->m2exp); break; } @@ -116,25 +113,25 @@ gmp_rand_init (s, size, alg) mpz_init_set_str (q, "315270837425234199477225845240496832591", 10); /* Allocate algorithm specific data. */ - s->data.bbs = (__gmp_rand_data_bbs *) + rstate->data.bbs = (__gmp_rand_data_bbs *) (*_mp_allocate_func) (sizeof (__gmp_rand_data_bbs)); - mpz_init (s->data.bbs->bi); /* The Blum integer. */ - mpz_mul (s->data.bbs->bi, p, q); + mpz_init (rstate->data.bbs->bi); /* The Blum integer. */ + mpz_mul (rstate->data.bbs->bi, p, q); /* Find a seed, x, with gcd (x, bi) == 1. */ mpz_init (ztmp); while (1) { - mpz_gcd (ztmp, seed, s->data.bbs->bi); + mpz_gcd (ztmp, seed, rstate->data.bbs->bi); if (!mpz_cmp_ui (ztmp, 1)) break; mpz_add_ui (seed, seed, 1); } - s->alg = alg; - s->size = size; /* FIXME: Remove. */ - mpz_set (s->seed, seed); + rstate->alg = alg; + rstate->size = size; /* FIXME: Remove. */ + mpz_set (rstate->seed, seed); mpz_clear (p); mpz_clear (q); |