5. Pseudo-Random Numbers
stdlib.h - rand(), srand(), RAND_MAXsrand( seed); // initialize rand() r = rand(); // generate pseudo-random number from 0 to RAND_MAXtime.h - time()
time(0) is current time in seconds since 1970Examples:
double d; int r, seed = time(0); srand(seed); // just once, at beginning of main r = rand(); // 0 <= r <= RAND_MAX r = rand() % (b-a+1) + a; // range of int, a <= r <= b d = (rand()/(double)RAND_MAX)*(b-a) + a; // range of double, a <= d <= bchapter4_5.c - print some values of rand
chapter4_6.c - print some random integers