in reply to Perl rand() generates larger numbers for small sample size, bug!

Possibly related to the number of random numbers - first from the built in rand and then with rand from Math::Random::MT::Auto. I generated 2 ** 25 random numbers and the code and results are below.
#!/usr/bin/perl use strict; use warnings; use 5.014; my %rand; for (1 .. 2**25) { my $r = rand; $rand{ $r }++; } say scalar keys %rand; use Math::Random::MT::Auto qw(rand); %rand = (); for (1 .. 2**25) { my $r = rand; $rand{ $r }++; } say scalar keys %rand;
Results:
C:\Old_Data\perlp>perl t.pl 32768 33554432 C:\Old_Data\perlp>perl -E "say 2**25" 33554432 C:\Old_Data\perlp>perl -E "say 2**15" 32768 C:\Old_Data\perlp>
You can see that for 2**25 == 33_554_432 the built in rand only produced 2**15 == 32768 random numbers but the module produced an entire range of random numbers equal to 2**25.

Update: perl version -
C:\Old_Data\perlp>perl -v This is perl 5, version 14, subversion 1 (v5.14.1) built for MSWin32-x64-multi-thread

Windows version - 7

Replies are listed 'Best First'.
Re^2: Perl rand() generates larger numbers for small sample size, bug!
by Anonymous Monk on Aug 08, 2014 at 17:13 UTC

    Provide more info on your perl version, etc? Unable to replicate this finding (on x86_64-linux):

    $ perl5.12.3 -we '$rand{ rand() }++ for 1..2**22; print int keys %rand +' 4194304 $ perl5.18.1 -we '$rand{ rand() }++ for 1..2**22; print int keys %rand +' 4194304