[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Shufflebug



>>>>> "abigail" == abigail  <abigail@delanet.com> writes:

>> You need to re-seed roughly
>> every 32/6 calls to rand (right Abigail?).

abigail> No. You will have to reseed after *EVERY CALL*. Think about it. It'll
abigail> be impossible for rand() to get the same outcome twice in a row (if it
abigail> would, it would never get anything else). But for a truely random (but
abigail> finite precision) generator, getting the same outcome twice in a row
abigail> has to be possible.

Uh, no, wait.  int(1 + rand 52) can return the same number twice.  in
fact, it uses up only log(52)/log(2) = 5.7 bits each time.  Can't we
show that for srand($_) for 0..2**32 that two calls to int(1 + rand
52) will cover every possibly combination nearly equally well?  And
that three calls use up only 17 bits?  And 4 calls uses up 23 bits?
So we could reseed every 4 calls to get 1..52 and still be "truly"
random, with some bits to spare.  5 if we want to cut it close.

Or am I totally fricked up on the math here?

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe