/* File: rand3.c Play with a random number generator. Third try. Using time to set the seed. */ #include #include #include #include "genlib.h" #include "simpio.h" main() { int i, j, go_ahead, time_seed ; while (TRUE) { printf("\nEnter 1 to continue: ") ; go_ahead = GetInteger() ; if (go_ahead != 1) break ; /* Use the time function to set the seed. */ time_seed = (int) time(0) ; printf("Setting seed to be: %d\n", time_seed) ; srand(time_seed) ; /* Print out 50 random numbers in a 10 x 5 grid */ for (i = 0 ; i < 10 ; i++) { for (j = 0 ; j < 5 ; j++) { printf("%8d ", rand() ) ; } printf("\n") ; } } }