C++ Programming/Code/Standard C Library/Functions/srand
< C++ Programming < Code < Standard C Library < Functionssrand
Syntax |
#include <cstdlib>
void srand( unsigned seed );
|
The function srand() is used to seed the random sequence generated by rand(). For any given seed, rand() will generate a specific "random" sequence over and over again.
srand( time(NULL) );
for( i = 0; i < 10; i++ )
printf( "Random number #%d: %d\n", i, rand() );
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.