delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1998/11/17/22:43:03

Sender: nate AT cartsys DOT com
Message-ID: <36524189.C36ECCCF@cartsys.com>
Date: Tue, 17 Nov 1998 19:39:53 -0800
From: Nate Eldredge <nate AT cartsys DOT com>
X-Mailer: Mozilla 4.05 [en] (X11; I; Linux 2.0.35 i486)
MIME-Version: 1.0
To: djgpp-workers AT delorie DOT com
Subject: Re: src/libc/ansi/stdlib/rand.c
References: <f65fe2d DOT 3650745b AT aol DOT com>
Reply-To: djgpp-workers AT delorie DOT com

Kbwms AT aol DOT com wrote:
> 
> Dear Eli Zaretskii,
> 
> On 11-16-98 at 04:25:17 EST you 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.'

I don't have a copy of the ANSI spec (it's not available online, is
it?), but the X/Open Unix spec says not calling `srand' is equivalent to
`srand(1)'.  I think it's a superset of ANSI/POSIX.

http://www.opengroup.org/onlinepubs/7908799/xsh/rand.html

`random' is supposed to work the same.

http://www.opengroup.org/onlinepubs/7908799/xsh/initstate.html

> > I think most people would expect `rand' to produce the same sequence
> > unless they called `srand', even if ANSI doesn't mandate it.
> >
> 
> You have a point.  But learned usage should prompt a user to call
> *srand* with the same parameter to get a deterministic result.

Empirically, it seems like most newbies expect it to produce different
sequences.  That doesn't mean they're right, however.  I agree that any
reasonable person would explicitly seed the RNG to get deterministic
results, but since when are standard writers reasonable? :-\

IMHO, this FAQ should lessen with the beta in any case now that the
`rand' docs make explicit mention that the RNG must be seeded.  If we
add a similar clause to the `random' docs, that should help even more.

I think we should stick with the standard in this instance.  (I've never
been entirely comfortable about the `printf' flushing, anyway...)

-- 

Nate Eldredge
nate AT cartsys DOT com

- Raw text -


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