December 2005
Beginner to intermediate
618 pages
20h 19m
English
srand
Initializes the random number generator
#include <stdlib.h> voidsrand( unsignedn);
The srand() function
initializes the random number generator using its argument
n as the “seed.” For each value of the
seed passed to srand(),
subsequent calls to rand() yield
the same sequence of “random” numbers. For this reason, a common
technique to avoid repetition is to seed srand() with the current time. If you call
rand() without having called
srand(), the result is the same
as if you had called srand() with
the argument value 1.
See the example for rand() in this
chapter.
Read now
Unlock full access