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

X-Authentication-Warning: acp3bf.physik.rwth-aachen.de: broeker owned process doing -bs
Date: Tue, 17 Nov 1998 14:06:41 +0100 (MET)
From: Hans-Bernhard Broeker <broeker AT physik DOT rwth-aachen DOT de>
X-Sender: broeker AT acp3bf
To: djgpp-workers AT delorie DOT com
Subject: Re: src/libc/ansi/stdlib/rand.c
In-Reply-To: <365079C2.5052B140@cyberoptics.com>
Message-ID: <Pine.LNX.3.93.981117135038.7061H-100000@acp3bf>
MIME-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com

On Mon, 16 Nov 1998, Eric Rudd wrote:

> I don't have my copy of C90 with me, but in the latest draft of C9x the
> behavior is defined even when srand() is not called first:
> 
> 7.20.2.2  The srand function
> 
>        Synopsis
> 
>        [#1]
> 
>                #include <stdlib.h>
>                void srand(unsigned int seed);
> 
>        Description
> 
>        [#2]  The  srand  function uses the argument as a seed for a
>        new sequence of pseudo-random  numbers  to  be  returned  by
>        subsequent  calls to rand.  If srand is then called with the
>        same seed value, the sequence of pseudo-random numbers shall
>        be  repeated.   If  rand is called before any calls to srand
>        have been made, the same sequence shall be generated as when
>        srand is first called with a seed value of 1.

Just for the record: this essentially unchanged from ANSI C89.

> No matter how rand() and srand() are implemented, someone is always going
> to be surprised.  The surprised party ought to be the careless programmer
> who hasn't read the C standard, rather than the careful programmer who has.

I second that. The standard is way too important to break compliance just
to please programmers who can't be bothered to read any kind of
documentation. 

And, to set that straight: this issue is fundamentally different from the
change in 2.02 to automatically fflush(stdout) after each printf().  That
detail is left open to the implementor, by the standard, so we don't
violate the standard either by the old way, nor be the proposed new one.
(We're just making stdout unbuffered, instead of line-buffered). 

Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.

- Raw text -


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