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
From:
Perl @ ResonatorSoft . org
Date:
November 27, 2012 06:59
Subject:
[perl #115928] rand() on Windows only uses 15 bits of entropy
Message ID:
rt-3.6.HEAD-17500-1354028345-497.115928-75-0@perl.org
# New Ticket Created by  Perl@ResonatorSoft.org 
# Please include the string:  [perl #115928]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=115928 >


This is a bug report for perl from Perl@ResonatorSoft.org,
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]
-----------------------------------------------------------------
---
Flags:
    category=core
    severity=medium
---
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:

  Platform:
    osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
    uname='Win32 strawberry-perl 5.16.0.1 #1 Mon May 21 22:07:30 2012 i386'
    config_args='undef'
    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
  Compiler:
    cc='gcc', ccflags =' -s -O2 -DWIN32  -DPERL_TEXTMODE_SCRIPTS
-DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -fno-strict-aliasing
-mms-bitfields',
    optimize='-s -O2',
    cppflags='-DWIN32'
    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"
-L"C:\strawberry\c\lib"'
    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
    gnulibc_version=''
  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:
    C:/STRAWBERRY/perl/site/lib/MSWin32-x86-multi-thread
    C:/STRAWBERRY/perl/site/lib
    C:/STRAWBERRY/perl/vendor/lib
    C:/STRAWBERRY/perl/lib
    .

---
Environment for perl 5.16.0:
    HOME (unset)
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=C:\Windows\SYSTEM32;C:\Windows;C:\Windows\SYSTEM32\WBEM;C:\Windows\SYSTEM32\WINDOWSPOWERSHELL\V1.0\;C:\STRAWBERRY\C\BIN;C:\STRAWBERRY\PERL\SITE\BIN;C:\STRAWBERRY\PERL\BIN;C:\CYGWIN\BIN;C:\CYGWIN\USR\BIN;C:\Program
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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About