Copyright 1999, 2000, 2002 Free Software Foundation, Inc.
This file is part of the GNU MP Library test suite.
The GNU MP Library test suite is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
The GNU MP Library test suite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */
/* Examples:
$ gen 10 10 integers 0 <= X < 2^32 generated by mpz_urandomb()
$ gen -f mpf_urandomb 10 10 real numbers 0 <= X < 1
$ gen -z 127 10 10 integers 0 <= X < 2^127
$ gen -f mpf_urandomb -x .9,1 10 10 real numbers 0 <= X < .9
int main (argc, argv) int argc; char *argv[];
{ constchar usage[] = "usage: gen [-bhpq] [-a n] [-c a,c,m2exp] [-C a,c,m] [-f func] [-g alg] [-m n] [-s n] " \ "[-x f,t] [-z n] [n]\n" \ " n number of random numbers to generate\n" \ " -a n ASCII output in radix n (default, with n=10)\n" \ " -b binary output\n" \ " -c a,c,m2exp use supplied LC scheme\n" \ " -f func random function, one of\n" \ " mpz_urandomb (default), mpz_urandomm, mpf_urandomb, rand, random\n" \ " -g alg algorithm, one of mt (default), lc\n" \ " -h print this text and exit\n" \ " -m n maximum size of generated number plus 1 (0<= X < n) for mpz_urandomm\n" \ " -p print used seed on stderr\n" \ " -q quiet, no output\n" \ " -s n initial seed (default: output from time(3))\n" \ " -x f,t exclude all numbers f <= x <= t\n" \ " -z n size in bits of generated numbers (0<= X <2^n) (default 32)\n" \ "";
unsignedlongint f; unsignedlongint n = 0; unsignedlongint seed; unsignedlongint m2exp = 0; unsignedint size = 32; int seed_from_user = 0; int ascout = 1, binout = 0, printseed = 0; int output_radix = 10; int lc_scheme_from_user = 0; int quiet_flag = 0;
mpz_t z_seed;
mpz_t z1;
mpf_t f1;
gmp_randstate_t rstate; int c, i; double drand; long lrand; int do_exclude = 0;
mpf_t f_xf, f_xt; /* numbers to exclude from sequence */ char *str_xf, *str_xt; /* numbers to exclude from sequence */ char *str_a, *str_adder, *str_m;
mpz_t z_a, z_m, z_mmax; unsignedlongint ul_adder;
enum
{
RFUNC_mpz_urandomb = 0,
RFUNC_mpz_urandomm,
RFUNC_mpf_urandomb,
RFUNC_rand,
RFUNC_random,
} rfunc = RFUNC_mpz_urandomb; char *rfunc_str[] = { "mpz_urandomb", "mpz_urandomm", "mpf_urandomb", "rand", "random" }; enum
{
RNG_MT = 0,
RNG_LC
};
gmp_randalg_t ralg = RNG_MT; /* Texts for the algorithms. The index of each must match the
corresponding algorithm in the enum above. */ char *ralg_str[] = { "mt", "lc" };
if (! seed_from_user)
mpz_set_ui (z_seed, (unsignedlongint) time (NULL));
seed = mpz_get_ui (z_seed); if (printseed)
{
fprintf (stderr, "gen: seed used: ");
mpz_out_str (stderr, output_radix, z_seed);
fprintf (stderr, "\n");
}
mpf_set_prec (f1, size);
/* init random state and plant seed */ switch (rfunc)
{ case RFUNC_mpf_urandomb: #if 0 /* Don't init a too small generator. */
size = PREC (f1) * GMP_LIMB_BITS; /* Fall through. */ #endif case RFUNC_mpz_urandomb: case RFUNC_mpz_urandomm: switch (ralg)
{ case RNG_MT:
gmp_randinit_mt (rstate); break;
case RNG_LC: if (! lc_scheme_from_user)
gmp_randinit_lc_2exp_size (rstate, MIN (128, size)); else
gmp_randinit_lc_2exp (rstate, z_a, ul_adder, m2exp); break;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.