srand
raw OCR
Initializes random number generator.
Defined in header <stdlib.h>
Syntax
#include <stdlib.h>
void srand (unsigned seed);
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ | ■ | ■ | ■ |
Remarks
The random number generator is reinitialized by calling srand with an argument value of 1. It can be set to a new starting point by calling srand with a given seed number.
Return value
None.
See also
Example
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main(void)
{
int i;
■time_t t;
srand((unsigned) time(&t));
printfC'Ten random numbers from 0 to 99\n\n");
for(i=0; i<10; i++)
printf("%d\n", randO % 100);
return 0;
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Stable link: /3.1/stdlib.h/srand/
· short form /3.1/srand/