I'm confused about this
John Gordon
gordon at osiris.cso.uiuc.edu
Wed Nov 21 13:54:59 AEST 1990
jmwojtal at vela.acs.oakland.edu (Wojo) writes:
>I got this C program and this part I don't understand:
>int getpid();
>long now;
>now = time(&now) / rand();
>srand(getpid() + (int)((now >> 16) + now + time(&now)));
>What does "srand" do to be exact? It doesn't bring a value back?
>"getpid()" is declared, but the function is not in the program.
srand() "seeds" the random-number generator, enabling it to produce
numbers that are more random than if you hadn't seeded it.
getpid() gets the process' ID number. This is usually a fairly
good choice for a random number.
So, the random-number generator is seeded with another random number.
This ensures very random results.
More information about the Comp.lang.c
mailing list