Date: Mon, 16 Nov 1998 10:19:55 +0200 (IST) From: Eli Zaretskii X-Sender: eliz AT is To: DJ Delorie cc: djgpp-workers AT delorie DOT com Subject: Re: src/libc/ansi/stdlib/rand.c In-Reply-To: <199811151915.OAA23094@indy.delorie.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp-workers AT delorie DOT com On Sun, 15 Nov 1998, DJ Delorie wrote: > static unsigned long long next = 0; > static int srand_called = 0; > > int > rand(void) > { > if (!srand_called) > { > unsigned int lsb, msb, tics; > outportb(0x43, 0x00); > lsb = inportb(0x40); > msb = inportb(0x40); > tics = _farpeekl(_dos_ds, 0x46c); > srand(lsb | (msb<<8) || (((long long)tics)<<16)); > } 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. > void > srand(unsigned seed) > { > next = seed; > srand_called = 1; > rand(); > rand(); > rand(); > } I think ANSI specifies that ``implementation shall behave as if no library function calls the `rand' function.'' If I'm right, this violates that requirement. (Why are the calls to `rand' a good idea, anyway?)