start a new sequence of pseudo-random integers
#include <stdlib.h> void srand( unsigned int seed );
The srand() function uses the argument seed to start a new sequence of pseudo-random integers to be returned by subsequent calls to rand(). A particular sequence of pseudo-random integers can be repeated by calling srand() with the same seed value. The default sequence of pseudo-random integers is selected with a seed value of 1.
#include <stdio.h>
#include <stdlib.h>
void main()
{
int i;
srand( 982 );
for( i = 1; i < 10; ++i ) {
printf( "%d\n", rand() );
}
srand( 982 ); /* start sequence over again */
for( i = 1; i < 10; ++i ) {
printf( "%d\n", rand() );
}
}
ANSI
| Safety: | |
|---|---|
| Interrupt handler | Yes |
| Signal handler | Yes |
| Thread | Yes |