Advertisement
thenewboston

Forum reply about srand()

Aug 24th, 2014
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.40 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <time.h>
  5.  
  6. int main()
  7. {
  8.    int i;
  9.    time_t t;
  10.  
  11.    // this creates your random number generator based on a new variable (time)
  12.    // since time changes constantly, the numbers generated will always be different
  13.    srand(time(&t));
  14.  
  15.    for( i = 0 ; i < 10 ; i++ ) {
  16.       printf("%d\n", rand()%6+1);
  17.    }
  18.  
  19.   return(0);
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement