/* nag_rngs_logarithmic (g05mdc) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpout; /* Scalars */ double a; Integer i, igen, n, nr; Integer exit_status = 0; NagError fail; /* Arrays */ double *r = 0; Integer *x = 0; Integer iseed[4]; INIT_FAIL(fail); /* Check for command-line IO options */ fpout = nag_example_file_io(argc, argv, "-results", NULL); fprintf(fpout, "nag_rngs_logarithmic (g05mdc) Example Program Results\n\n"); nr = 1; n = 10; /* Allocate memory */ if (!(r = NAG_ALLOC(nr, double)) || !(x = NAG_ALLOC(n, Integer))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } /* Set the distribution parameter A */ a = 0.9999; /* Initialise the seed to a repeatable sequence */ iseed[0] = 1762543; iseed[1] = 9324783; iseed[2] = 42344; iseed[3] = 742355; /* igen identifies the stream. */ igen = 1; /* nag_rngs_init_repeatable (g05kbc). * Initialize seeds of a given generator for random number * generating functions (that pass seeds explicitly) to give * a repeatable sequence */ nag_rngs_init_repeatable(&igen, iseed); /* Generate integers and store in X */ /* Use MODE=3 because A > 0.95 */ /* nag_rngs_logarithmic (g05mdc). * Generates a vector of random integers from a logarithmic * distribution, seeds and generator number passed * explicitly */ nag_rngs_logarithmic(3, a, n, x, igen, iseed, r, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_rngs_logarithmic (g05mdc).\n%s\n", fail.message); exit_status = 1; goto END; } for (i = 0; i < n; ++i) { fprintf(fpout, "%12ld\n", x[i]); } END: if (fpout != stdout) fclose(fpout); if (r) NAG_FREE(r); if (x) NAG_FREE(x); return exit_status; }