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: #if0 /* 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.