/* nag_rngs_sample(g05nbc) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include int main(void) { /* Scalars */ Integer i, igen, k, m, n; Integer exit_status=0; NagError fail; /* Arrays */ Integer *ipop=0, *isampl=0; Integer iseed[4]; INIT_FAIL(fail); Vprintf("g05nbc Example Program Results\n\n"); n = 8; /* Allocate memory */ if ( !(ipop = NAG_ALLOC(n, Integer)) || !(isampl = NAG_ALLOC(n, Integer)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } /* Initialise the seed to a repeatable sequence */ iseed[0] = 1762543; iseed[1] = 9324783; iseed[2] = 1542344; iseed[3] = 742355; /* igen identifies the stream. */ igen = 1; g05kbc(&igen, iseed); Vprintf(" Samples from the first %1ld integers\n", n); Vprintf("\n"); Vprintf(" Sample size Values\n"); for (i = 0; i < n; ++i) ipop[i] = i+1; for (m = 1; m <= n; ++m) { g05nbc(ipop, n, isampl, m, igen, iseed, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from g05nbc.\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("%6ld ", m); for (k = 0; k < m; ++k) { Vprintf("%3ld%s", isampl[k], (k+1)%8 == 0 || k == m-1 ?"\n":" "); } } END: if (ipop) NAG_FREE(ipop); if (isampl) NAG_FREE(isampl); return exit_status; }