[EMAIL PROTECTED] (Chris Wagner) graced perl with these words of
wisdom:
> Just for fun I did a little test.
> for (1 .. 10000) {
> my $fn = rand();
> ++$dup and next if exists $num{$fn};
> $num{$fn} = 1;
> }
> print scalar keys %num, " unique numbers. $dup duplicates produced\n";
> #########
> 8623 unique numbers. 1377 duplicates produced
>
> That's really interesting. So rand() is pretty useless.
I'm not surprised it would produce 1300+ duplicates. If anything, I'd
expect it to produce more. Suppose you play a Pick-4 lottery (four-digit
number with leading 0's allowed), which has 10000 possible combinations.
Some states have a "Quick Pick" option that will "randomly" pick one of
the combinations for you when you go to make your pick. If you assume
that the randomness of the "Quick Pick" is truly random, and play 10000
Quick Picks, the chances you *won't* have the winning number are close to
1/e, which is about 37%:
The chance of not winning is (1-(1/n))^n, which as n -> oo approaches 1/e
-- at least, I think this is what I learned in my high school calculus
class!
You weren't expecting *fewer* duplicates, were you?
--
Ted <fedya at bestweb dot net>
Oh Marge, anyone can miss Canada, all tucked away down there....
--Homer Simpson
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs