----- Original Message ----- From: "Ted Schuerzinger" <[EMAIL PROTECTED]> To: <Perl-Win32-Users@listserv.ActiveState.com> Sent: Friday, December 02, 2005 2:53 AM Subject: Hash limits? (Was: Re: rand() not so random)
> [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"; > > > > Just for fun, I changed one of the lines in that to > > for (1 .. 1000000) { > > When I ran the modified script, I got 32768 unique numbers, with 967232 > duplicates! As 32768 is a power of 2, I'm wondering if there's a limit on > the number of keys one may have in a hash. > I think it's just that there are only 2 ** $Config{randbits} distinct numbers that rand() will output. You'll probably find that $Config{randbits} for you is 15 .... and 2 ** 15 == 32768. ie, with 15 bits, you can represent only 32768 different numbers. Cheers, Rob _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs