5. Pseudo-Random Numbers

stdlib.h - rand(), srand(), RAND_MAX
  srand( seed); // initialize rand()

  r = rand();   // generate pseudo-random number from 0 to RAND_MAX
time.h - time()
  time(0) is current time in seconds since 1970
Examples:
  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 <= b
chapter4_5.c - print some values of rand

chapter4_6.c - print some random integers

Example rand implementation

Example rand implementation output