/* nag_restore_random_state (g05cgc) Example Program. * * Copyright 1990 Numerical Algorithms Group. * * Mark 1, 1990. */ #include #include #include #include int main(void) { Integer exit_status = 0; Integer seed = 0; Integer i, istate[9]; double x[5], xstate[4]; NagError fail; INIT_FAIL(fail); printf("nag_restore_random_state (g05cgc) Example Program Results\n"); /* nag_random_init_repeatable (g05cbc). * Initialize random number generating functions to give * repeatable sequence */ nag_random_init_repeatable(seed); for (i = 0; i < 5; ++i) { /* nag_random_continuous_uniform (g05cac). * Pseudo-random real numbers, uniform distribution over * (0,1) */ x[i] = nag_random_continuous_uniform(); if (i == 1) /* nag_save_random_state (g05cfc). * Save state of random number generating functions */ nag_save_random_state(istate, xstate); } for (i = 0; i < 5; ++i) printf("%9.4f%s", x[i], (i%5 == 4 || i == 4)?"\n":" "); for (i = 0; i < 5; ++i) { /* nag_random_continuous_uniform (g05cac), see above. */ x[i] = nag_random_continuous_uniform(); if (i == 1) { /* nag_restore_random_state (g05cgc). * Restore state of random number generating functions */ nag_restore_random_state(istate, xstate, &fail); if (fail.code != NE_NOERROR) { printf( "Error from nag_restore_random_state (g05cgc) %s\n", fail.message); exit_status = 1; goto END; } } } for (i = 0; i < 5; ++i) printf("%9.4f%s", x[i], (i%5 == 4 || i == 4)?"\n":" "); END: return exit_status; }