/* nag_save_random_state (g05cfc) Example Program. * * Copyright 1990 Numerical Algorithms Group. * * Mark 1, 1990. */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpout; Integer exit_status = 0; Integer seed = 0; Integer i, istate[9]; double x[5], xstate[4]; NagError fail; INIT_FAIL(fail); /* Check for command-line IO options */ fpout = nag_example_file_io(argc, argv, "-results", NULL); fprintf(fpout, "nag_save_random_state (g05cfc) 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) fprintf(fpout, "%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) { fprintf(fpout, "Error from nag_save_random_state (g05cfc) %s\n", fail.message); exit_status = 1; goto END; } } } for (i = 0; i < 5; ++i) fprintf(fpout, "%9.4f%s", x[i], (i%5 == 4 || i == 4)?"\n":" "); END: if (fpout != stdout) fclose(fpout); return exit_status; }