[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [ProgSoc] Randomisation
On Tue, Feb 02, 1999 at 08:08:19AM +1100, Peter Meric wrote:
> On Tue, 2 Feb 1999, Matt Beauregard wrote:
> > > srand(time(NULL));
> > If there's a possibility that the program will be run twice in the same
> > second you might want to combine time() with, say, getpid() to mix
> > things up a bit.
> This merely initialises the RNG. Probably no need to do it twice in any
> given second.
You're missing the point: if the program is run twice in the same second, using time() to set the seed will result in the seed being the same both times. By bitwise-combining time() with getpid() you lessen the likelihood of getting the same stream of numbers in two consecutive runs of the program, which is a very real danger for networked or short-run programs. You're not seeding it twice, just seeding it better.
screen so pure and blue
this computer is at peace
control alt delete
You are subscribed to the progsoc mailing list. To unsubscribe, send a
message containing "unsubscribe" to email@example.com.
If you are having trouble, ask firstname.lastname@example.org for help.
This list is archived at <http://www.progsoc.uts.edu.au/lists/progsoc/>