srand


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( )



C(c) In a Nutshell
C in a Nutshell (In a Nutshell (OReilly))
ISBN: 0596006977
EAN: 2147483647
Year: 2006
Pages: 473

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net