Re: rand() and srand() broken?
Re: rand() and srand() broken?
- Subject: Re: rand() and srand() broken?
- From: Clark Cox <email@hidden>
- Date: Wed, 25 Nov 2009 15:18:17 -0500
On Wed, Nov 25, 2009 at 2:47 PM, Derek Gaston <email@hidden> wrote:
> On Nov 25, 2009, at 12:41 PM, Clark Cox wrote:
>
>> Yes. If you pass the same value to seed(), you will get the same
>> sequence of values from rand(). Period. Any implementation of
>> srand/rand that does not do this is broken. From the C Standard:
>
> Indeed... note that this wasn't about passing the _same_ value... it was about passing similar values to srand... like singularly increasing integers...
I was responding specifically to:
"Are you (and everyone else that replied) trying to tell me that the
first number out of rand() (after reseeding) should always be the
predictable?"
And, the answer is yes. The first number out of rand (as well as every
subsequent number for that matter) is 100% predictable after
re-seeding.
By definition, the value that comes out of rand is directly related to
the value passed into srand, because it is a PRNG. You will never get
truly random numbers out of rand. The only way that you will even get
close is to seed it with a single, hard-to-predict value (the time, a
random number from a true RNG, etc.), *any* other use of rand will not
guarantee you numbers that are anywhere near random.
--
Clark S. Cox III
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden