Previous Page
Next Page

srand

Initializes the random number generator

#include <stdlib.h>
void srand ( unsigned n  );

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

rand( )


Previous Page
Next Page