/* nag_rngs_geom (g05mbc) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include int main(void) { /* Scalars */ double p; Integer igen, j, n, nr; Integer exit_status=0; NagError fail; /* Arrays */ double *r=0; Integer *x=0; Integer iseed[4]; INIT_FAIL(fail); Vprintf("nag_rngs_geom (g05mbc) Example Program Results\n\n"); nr = 40000; n = 10; /* Allocate memory */ if ( !(r = NAG_ALLOC(nr, double)) || !(x = NAG_ALLOC(n, Integer)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } /* Set the distribution parameter P */ p = 0.001; /* Initialise the seed to a repeatable sequence */ iseed[0] = 1762543; iseed[1] = 9324783; iseed[2] = 423441; 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); /* Choose MODE = 3 because P is close to 0 */ /* nag_rngs_geom (g05mbc). * Generates a vector of random integers from a geometric * distribution, seeds and generator number passed * explicitly */ nag_rngs_geom(3, p, n, x, igen, iseed, r, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_rngs_geom (g05mbc).\n%s\n", fail.message); exit_status = 1; goto END; } for (j = 0; j < n; ++j) { Vprintf("%12ld\n", x[j]); } END: if (r) NAG_FREE(r); if (x) NAG_FREE(x); return exit_status; }