The NRC Handelsblad this Saturday had an article about pseudo-random number sequences. They mentioned the work of Heiko Bauke and Stephan Mertens: Entropy of Pseudo Random Numbers. According to the article in the NRC, it seems that many random number generators tend to generate longer sequences of zero's than you might want or expect. The article also claims that Bauke and Mertens indicate that by removing the 0's from random number sequences, you improve the quality of the random number sequence. I've tried to make heads or tails from the original article by Bauke and Mertens, but it is waaay out of my league. So I hope the assumptions of the NRC article are correct.

Anyway, I decided to see whether the standard Perl random number generator would suffer from this problem, and created the following program:

use strict;
my @freq;
my @same;
use constant MAX => 10;
my $running = 1;
$SIG{INT} = sub { $running = 0 }; # keep running until Control-C'd
while ($running) {
my $value = int rand MAX;
$freq[$value]++;
substr( $_,0,0 ) = $value;
s#^((.)\2*)(.*)#$1#s;
next unless length( $3 ) > 1;
$same[substr $3,0,1]->{length $3}++;
}
my $total;
foreach (0..MAX-1) {
$total += $freq[$_];
my $ref = $same[$_];
print qq{\n$_($freq[$_]): @{[map {"$_($ref->{$_}x)"} sort {$a <=>
+$b} keys %{$ref}]}};
}
print "\n$total total\n";

The program basically draws random numbers and puts them into a string. A regular expression is used to find out whether the number was the same as the previous time. If not, it will score the number of times the previously drawn random number was drawn consecutively.

The program will run until interrupted with a Control-C. Then it will display the result.

I let this run on my iBook last night (I guess in total for about 9 hours or so) and came up with the following results.

Looking at these numbers, I would think that either:

Perl doesn't suffer from the described problem.

and/or my test program is faulty (not too unlikely, I might add).

and/or the sample is still too small to show the problem.

If 3. is true, then I don't think any "normal" use of Perl would need to worry. I can't remember ever drawing close to 2G random numbers in a single run ;-)

Since this was fun to do, I'd thought I'd share this.