/* nag_restore_random_state (g05cgc) Example Program. * * Copyright 1990 Numerical Algorithms Group. * * Mark 1, 1990. */ #include #include #include #include int main(void) { Integer seed = 0; Integer i, istate[9]; double x[5], xstate[4]; Vprintf("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) Vprintf("%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, NAGERR_DEFAULT); } for (i=0; i<5; ++i) Vprintf("%9.4f%s", x[i], (i%5==4 || i==4) ? "\n": " "); return EXIT_SUCCESS; }