Mail Archives: djgpp-workers/1998/11/17/04:07:17
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 -