Date: Mon, 16 Nov 1998 10:13:31 -0500 (EST) Message-Id: <199811161513.KAA11191@indy.delorie.com> From: DJ Delorie To: eliz AT is DOT elta DOT co DOT il CC: djgpp-workers AT delorie DOT com In-reply-to: (message from Eli Zaretskii on Mon, 16 Nov 1998 10:19:55 +0200 (IST)) Subject: Re: src/libc/ansi/stdlib/rand.c Reply-To: djgpp-workers AT delorie DOT com > Doesn't this violate the ANSI Standard? My references indicate that > it requires the implementation to ``behave as if the target > environment calls "srand(1)" at program startup.'' (Which also means > that `next' should start with 1, not 0.) > > I think most people would expect `rand' to produce the same sequence > unless they called `srand', even if ANSI doesn't mandate it. The mail shows that people expect rand() to return a different random sequence each time they run their program, and I'm tired of this FAQ, so I figured I'd let libc randomize itself if srand() wasn't called at all. People who expect predictable sequences should call srand anyway, because they'll need to try different predictable sequences, not just the default one. > violates that requirement. (Why are the calls to `rand' a good idea, > anyway?) The seed is 64-bits, but the parameter is only 32 bits. Calling rand a few times gets the value "into the domain" of random numbers. I can take it out if it bothers people, but I figured it would make things a little more pseudorandom for the first couple of calls to rand() after srand().