srand -- Initialize Random Number Generator


SYNOPSIS
#include <stdlib.h>
void srand(unsigned int seed);
DESCRIPTION
srand
resets the number generator to a new starting point. The
rand
function then uses this seed
to generate a sequence of
pseudorandom numbers. The initial default seed
is 1.
RETURN VALUE
srand
has no return value.
PORTABILITY
See the portability details for rand
for more information.
EXAMPLE
This example uses srand
to print 1,000 random numbers:
#include <stdio.h>
#include <stdlib.h>
main(int argc, char *argv[])
{
int i, x;
if (argc > 1){
x = atoi(argv[i]);
if (x == 0){
x = 1;
}
printf("Seed value is %dn",x);
srand(x);
}
puts("Here are 1000 random numbers:");
for (i = 0; i < 200; i++){
printf("%5d %5d %5d %5d %5dn",
rand(),rand(),rand(),rand(),rand());
}
puts("n");
}
RELATED FUNCTIONS
rand
SEE ALSO
Mathematical Functions