develooper Front page | perl.perl5.porters | Postings from November 2012

[perl #115928] rand() on Windows only uses 15 bits of entropy

Thread Previous | Thread Next
Perl @ ResonatorSoft . org
November 27, 2012 06:59
[perl #115928] rand() on Windows only uses 15 bits of entropy
Message ID:
# New Ticket Created by 
# Please include the string:  [perl #115928]
# in the subject line of all future correspondence about this issue. 
# <URL: >

This is a bug report for perl from,
generated with the help of perlbug 1.39 running under perl 5.16.0.

[Please describe your issue here]

The Win32 version of Perl doesn't seem to generate random numbers
very well at all, especially in comparison to the Linux version.

Here's an example script detailing the problem:

my %nums;
my $cnt = 0;
foreach my $i (1 .. 1_000_000) {
   my $num = rand;
   $cnt++ if ($nums{$num});
   $nums{$num} = 1;
print "$cnt out of 1,000,000\n";

The purpose of the script is to reveal how many duplicate numbers
were generated out of a random sample of one million total numbers.
For Windows, this will output "967232 out of 1,000,000" every time.
In other words, there are only 32768 possible combinations of
"between 0 and 1" floats that rand() will generate.

If I test this same script on a Debian Linux box, I actually get no
dupes, meaning that it has a MUCH higher entropy.

[Please do not change anything below this line]
Site configuration information for perl 5.16.0:

Configured by strawberry-perl at Mon May 21 22:08:30 2012.

Summary of my perl5 (revision 5 version 16 subversion 0) configuration:

    osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
    uname='Win32 strawberry-perl #1 Mon May 21 22:07:30 2012 i386'
    hint=recommended, useposix=true, d_sigaction=undef
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=undef, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
    cc='gcc', ccflags =' -s -O2 -DWIN32  -DPERL_TEXTMODE_SCRIPTS
    optimize='-s -O2',
    ccversion='', gccversion='4.6.3', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='long
long', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='g++', ldflags ='-s -L"C:\strawberry\perl\lib\CORE"
    libpth=C:\strawberry\c\lib C:\strawberry\c\i686-w64-mingw32\lib
    libs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32
-ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32
-lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
    perllibs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool
-lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid
-lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
    libc=, so=dll, useshrplib=true, libperl=libperl516.a
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-mdll -s
-L"C:\strawberry\perl\lib\CORE" -L"C:\strawberry\c\lib"'

Locally applied patches:

@INC for perl 5.16.0:

Environment for perl 5.16.0:
    HOME (unset)
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
Files\TortoiseSVN\bin;C:\Program Files\Graphviz 2.28\bin;C:\Program
Files\TortoiseGit\bin;c:\Program Files\Microsoft SQL
Server\100\Tools\Binn\VSShell\Common7\IDE\;c:\Program Files\Microsoft
SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft Visual Studio
9.0\Common7\IDE\PrivateAssemblies\;c:\Program Files\Microsoft SQL
Server\100\DTS\Binn\;C:\Program Files\Nmap
    PERL_BADLANG (unset)
    SHELL (unset)

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About