/* nag_rngs_permute (g05nac) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include int main(void) { /* Scalars */ Integer i, igen, j, k, m, n; Integer exit_status=0; NagError fail; /* Arrays */ Integer *index=0; Integer iseed[4]; INIT_FAIL(fail); Vprintf("nag_rngs_permute (g05nac) Example Program Results\n\n"); n = 8; m = 10; /* Allocate memory */ if ( !(index = 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] = 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); Vprintf("%2ld Permutations of first %1ld integers\n", m, n); Vprintf("\n"); for (j = 0; j < m; ++j) { for (i = 0; i < n; ++i) index[i] = i + 1; /* nag_rngs_permute (g05nac). * Pseudo-random permutation of an integer vector */ nag_rngs_permute(index, n, igen, iseed, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_rngs_permute (g05nac).\n%s\n", fail.message); exit_status = 1; goto END; } for (k = 0; k < n; ++k) { Vprintf("%3ld%s", index[k], (k+1)%8 == 0 || k == n-1 ?"\n":" "); } } END: if (index) NAG_FREE(index); return exit_status; }