Re: Hash limits? (Was: Re: rand() not so random)
At 10:53 AM 12/1/2005 -0500, Ted Schuerzinger wrote: Just for fun, I changed one of the lines in that to for (1 .. 100) { 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. Heh, I did that too, but kept it a secret. That tells me rand is a very weak function. I think the 2^15 answer u got is a coincidence. Do it 5 times, u'll get 5 answers. It doesn't have anything to do with the hash itself. (AFAIK) It only gets invoked upon a *duplicate*, not a unique. The no. of keys is 967232. -- REMEMBER THE WORLD TRADE CENTER ---= WTC 911 =-- ...ne cede malis 0100 ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Hash limits? (Was: Re: rand() not so random)
Wait, I screwed up that last email. The uniques is the number of hash keys. At 10:53 AM 12/1/2005 -0500, Ted Schuerzinger wrote: for (1 .. 1) { 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 .. 100) { 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. -- REMEMBER THE WORLD TRADE CENTER ---= WTC 911 =-- ...ne cede malis 0100 ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Hash limits? (Was: Re: rand() not so random)
On Thu, 1 Dec 2005 12:05:11 -0800, you wrote: [EMAIL PROTECTED] (Chris Wagner) graced perl with these words of wisdom: Just for fun I did a little test. for (1 .. 1) { 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 .. 100) { 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. No, it's a limit on the number of values rand() produces on Windows, as this one-liner shows: perl -MConfig -e print $Config{randbits} randbits is the number of bits in the value produced by rand(); the value is 15 in ActiveState Perl for Windows. If you want a better random number generator, there are modules available on the PPM repositories; search for random. -- Eric Amick Columbia, MD ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Hash limits? (Was: Re: rand() not so random)
- 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 .. 1) { 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 .. 100) { 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
RE: Hash limits? (Was: Re: rand() not so random)
On Thu, 01 Dec 2005, Ted Schuerzinger wrote: Just for fun I did a little test. for (1 .. 1) { 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 .. 100) { 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. No, there isn't. But rand() uses only 15 bits in the default implementation, so you cannot generate more than 2**15 different values: C:perl -V:randbits randbits='15'; Cheers, -Jan ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs