Name
srand
Synopsis
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.
Example
See the example for rand()
in this
chapter.
See Also
Get C in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.