delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1998/11/17/04:07:17

Date: Tue, 17 Nov 1998 10:59:42 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Kbwms AT aol DOT com
cc: djgpp-workers AT delorie DOT com
Subject: Re: src/libc/ansi/stdlib/rand.c
In-Reply-To: <f65fe2d.3650745b@aol.com>
Message-ID: <Pine.SUN.3.91.981117105925.14078D-100000@is>
MIME-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com

On Mon, 16 Nov 1998 Kbwms AT aol DOT com wrote:

> > 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.)
> 
> Please cite the references.  As nearly as I can determine, and as stated
> in "The Standard C library," (page 350) 'The behavior of *rand* can vary
> among implementations.'

If that's Plauger's book, look on p.337, where it cites para 7.10.2.2
from the Standard, and also look on p.351 under `srand'.

> > 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?)
> 
> The extra calls cleanse the generator.  I'd like to see about 50 calls
> but three might be enough.

Except that 7.10.2.1 in the Standard says no library function should
call `rand', or at least the library should behave is if it doesn't.

The rationale behind this requirement, as I understand it, is that
once your application starts a random sequence, it should have total
control on the produced sequence.  If some library function calls
`rand', some of the generated random numbers will be ``stolen'' and
won't be seen by the application.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019