C examples for stdlib.h:srand
function
<cstdlib> <stdlib.h>
Initialize random number generator
void srand (unsigned int seed);
Parameter | Description |
---|---|
seed | An integer value to be used as seed by the pseudo-random number generator algorithm. |
none
#include <stdio.h> #include <stdlib.h> #include <time.h> int main ()// www . ja v a2 s .c o m { printf ("First number: %d\n", rand()%100); srand (time(NULL)); printf ("Random number: %d\n", rand()%100); srand (1); printf ("Again the first number: %d\n", rand()%100); return 0; }