Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 3 Feb 2003 13:35:16 +0100
From:      Erik Trulsson <ertr1013@student.uu.se>
To:        Thomas David Rivers <rivers@dignus.com>
Cc:        ache@nagual.pp.ru, kris@obsecurity.org, current@FreeBSD.ORG
Subject:   Re: Final fix for correlation problem (was Re: rand() is broken)
Message-ID:  <20030203123516.GA42430@falcon.midgard.homeip.net>
In-Reply-To: <200302031201.h13C1oE03172@lakes.dignus.com>
References:  <20030203114629.GA77557@nagual.pp.ru> <200302031201.h13C1oE03172@lakes.dignus.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Feb 03, 2003 at 07:01:50AM -0500, Thomas David Rivers wrote:
> I'm afraid I don't understand the fix... and how it
> seems to affect the historical behaviour of srand()/rand().
> 
> How does it address the understanding that if I use
> srand(28), I will get exactly the same sequence of
> numbers srand(28) produced yesterday, last week, 
> last year?

That understanding is mistaken.

> 
> I have worked with programs that depend on exactly
> that behavior.

Then those programs have a bug.
If you need every execution of the program to use the exact same
sequence of pseudo-random numbers then the program need to implement
its own RNG.


> 
> That is,  given the same input seed - I expect
> to see the same "random" sequence again.  

You will - if you generate both sequences during the same program
execution.
There are no guarantees (and has never been) that srand()/rand() will
give the same sequence after an OS update or on a different system or
even between two different runs of the same program.


> 
> This requirement would seem to indicate that changing
> srand()/rand() isn't really possible...  And, also,
> I believe, why random() was introduced...

a) srand()/rand() does use different algorithms on different systems so
   depending on some particular algorithm is inherently unportable.
b) random() was not introduced because the sequence from rand()
   couldn't be changed.  It was rather because the calling interface
   for srand()/rand() puts constraints on the implementation that result
   in rand() by necessity being a rather poor RNG.  random() was
   introduced so one could have a RNG with better statistical properties.
c) I believe the algorithm used by rand() *was* changed in -CURRENT
   about two years ago.  (And pretty the same discussion ensued back
   then.)  This change was done because the old algorithm used was
   particularly poor and it was possible to do better.  Now some defect
   in the new algorithm has apparently been discovered which is why it
   needs to be modified again.


> 
> Please, oh please, don't change that behavior in 
> srand()/rand().
> 
> 	- Dave Rivers -



-- 
<Insert your favourite quote here.>
Erik Trulsson
ertr1013@student.uu.se

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030203123516.GA42430>