/* File: rand4.c

   Play with a random number generator.
   Fourth try.  Using time to set the seed.
   Also, generate numbers between 1 and 6.
*/

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "genlib.h"
#include "simpio.h"

main() {
   int i, j, go_ahead, time_seed ;
   int r ;

   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++) {
	    r = rand() % 6 + 1 ;
	    printf("%8d ", r ) ;
	 } 
         printf("\n") ;
      }
   }
}
