Generating random numbers in C
Taken from the book, C Programming in Easy Steps.
The stdlib.h header file provides a rand() function that will generate a pseudo-random postitive integer when called. This will, by default return a number in the range to a large value (at least 32,767). A specific range can be set by using the modulus operator to specify a maximum upper limit. For example, to specify a range from 0 to 9 with the expression rand() % 9 the same sequence of numbers To set a minimum lower limit for the range, its value can be added to the result of the expression. For example, to specify a range from 1 to 10 with the expression ( rand() % 9) + 1.
The numbers generated by the rand() function are not truly random as the function successively generates the same sequence of numbers the "seed" that starts the sequence must be specified. By default the initial seed value is 1 but this can be changed by specifying alternative integer argument to the srand() function. For e