/* nag_rngs_compd_poisson (g05mec) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include int main(void) { /* Scalars */ Integer i, igen, j, m, n; Integer exit_status = 0; NagError fail; /* Arrays */ double *vlamda = 0; Integer *x = 0; Integer iseed[4]; INIT_FAIL(fail); printf("nag_rngs_compd_poisson (g05mec) Example Program Results\n\n"); m = 5; n = 10; /* Allocate memory */ if (!(vlamda = NAG_ALLOC(m, double)) || !(x = NAG_ALLOC(m, Integer))) { printf("Allocation failure\n"); exit_status = -1; goto END; } /* Set the distribution parameter LAMBDA */ vlamda[0] = 0.5; vlamda[1] = 5.0; vlamda[2] = 10.0; vlamda[3] = 500.0; vlamda[4] = 1e3; /* Initialise the seed to a repeatable sequence */ iseed[0] = 1762543; iseed[1] = 9324783; iseed[2] = 423442; 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 */ for (i = 0; i < n; ++i) { /* nag_rngs_compd_poisson (g05mec). * Generates a vector of random integers from a Poisson * distribution with varying mean, seeds and generator * number passed explicitly */ nag_rngs_compd_poisson(m, vlamda, x, igen, iseed, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_rngs_compd_poisson (g05mec).\n%s\n", fail.message); exit_status = 1; goto END; } for (j = 0; j < m; ++j) { printf("%12ld%s", x[j], (j+1)%5 == 0 || j == 4?"\n":" "); } } END: if (vlamda) NAG_FREE(vlamda); if (x) NAG_FREE(x); return exit_status; }