The Snowcrash Test

Random Number Generation and Testing

This particular version of the test shows how choosing successive values of a seed cause the random number generator to make somewhat similar sequences.

A Picture from the Test

The Code for this Test

#!/usr/bin/perl

=pod
  Program to show how random number generator is influenced by its seed
  by Tom Anderson   http://tomacorp.com
  Copyright 2001 all rights reserved.
  Permission to distribute available from t@tomacorp.com
=cut

  use strict;
  use PDL;
  use PDL::Graphics::PGPLOT;

  my $win = PDL::Graphics::PGPLOT::Window->new({Device => '/XSERVE/index.html'});
  my ($num_seeds, $num_rand_calls)= (150,150);
  $win->env( 0, $num_rand_calls, 0, $num_seeds );

  my @ra;
  for (my $s=0; $s<$num_seeds; $s++)
  {
    srand $s;
    for (my $x=0; $x<$num_rand_calls; $x++)
    {
      $ra[$s][$x]= rand;
    }
  }

  my $im= new PDL @ra;
  $win->label_axes('Number of calls to random number generator after seeding', 
                   'Seed', 'Random Numbers Displayed as Greyscale');
  $win->imag($im);

04/21/2002

By toma