in reply to Perl rand() generates larger numbers for small sample size, bug!
Results:#!/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;
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.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>
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 |