/* nag_rngs_gen_discrete(g05mzc) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include int main(void) { /* Initialized data */ static double p[] = { 0.01,0.02,0.04,0.08,0.2,0.3,0.2,0.08,0.04,0.02,0.01 }; /* Scalars */ Integer i, igen, ip1, np, n, nr; Integer exit_status=0; NagError fail; Nag_ComputeType itype; /* Arrays */ double *r=0; Integer *x=0; Integer iseed[4]; INIT_FAIL(fail); Vprintf("g05mzc Example Program Results\n\n"); nr = 60; n = 20; np = 11; /* 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 parameters P and M */ ip1 = -5; itype = Nag_Compute_1; /* 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; g05kbc(&igen, iseed); /* Choose MODE = 2 */ g05mzc(2, p, np, ip1, itype, n, x, igen, iseed, r, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from g05mzc.\n%s\n", fail.message); exit_status = 1; goto END; } for (i = 0; i < n; ++i) { Vprintf("%12ld\n", x[i]); } END: if (r) NAG_FREE(r); if (x) NAG_FREE(x); return exit_status; }