Random Perl Content
Randy J. Ray
rjray at blackperl.com
Sun May 19 04:14:36 BST 2013
Excellent feedback from everyone!
While reading the ideas, it occurred to me how simple it would be to
test Math::Random::MT (based loosely on Ruud's testing of Rand48). It
turns out that you *can* in fact instantiate completely independent
RNG's from ::MT. I banged out the following:
#!/usr/bin/env perl
use strict;
use warnings;
use autodie qw(open close);
use Math::Random::MT;
my ($fh, $ground, $noise, $noise1, $noise2);
my $iters = shift(@ARGV) || 10000;
# 1. Baseline. Generate $iters numbers with no other RNG's running.
open $fh, '>', 'rng-1';
$ground = Math::Random::MT->new(5);
for (1 .. $iters)
{
print {$fh} $ground->irand, "\n";
}
close $fh;
undef $ground;
# 2. Generate the same list with one other RNG running as well.
open $fh, '>', 'rng-2';
$ground = Math::Random::MT->new(5);
$noise = Math::Random::MT->new($$);
for (1 .. $iters)
{
$noise->rand();
print {$fh} $ground->irand, "\n";
}
close $fh;
undef $ground;
undef $noise;
# 3. Generate the same list with two other RNGs running as well.
open $fh, '>', 'rng-3';
$ground = Math::Random::MT->new(5);
$noise1 = Math::Random::MT->new($$);
$noise2 = Math::Random::MT->new(time);
for (1 .. $iters)
{
$noise1->rand();
print {$fh} $ground->irand, "\n";
$noise2->rand();
$noise2->irand();
}
close $fh;
undef $ground;
undef $noise1;
undef $noise2;
print "Done!\n";
exit;
Then I diff'd rng-1 against rng-2 and rng-3. Identical. And speedy,
too... generated the 3 sets of 10,000 pretty much instantly.
Now I just have to get it installed site-wide at work, a process that
can take weeks, if not months... (and no smart remarks about local::lib,
cpanm, etc... this is a large corporate environment with its own rules
and ways of doing things, unfortunately.)
Randy
--
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
Randy J. Ray Sunnyvale, CA http://www.rjray.org
rjray at blackperl.com
twitter.com/rjray
Silicon Valley Scale Modelers: http://www.svsm.org
More information about the london.pm
mailing list