#!/usr/bin/perl use strict; use warnings; use List::Util qw/ shuffle /; use Statistics::Descriptive; my @contaminated_walks; for (1 .. 100) { my $contaminated = 100; my $grid_rows = 100; my $grid_cols = 100; my $steps = 100; my $num_walks = 100; my @walks; for (1 .. $num_walks) { my @grid = # 1's and 0's randomly ordered shuffle( (1) x $contaminated, (0) x ($grid_rows * $grid_cols - $contaminated) ); # for each walk, 'grep' gets the count of contaminated cells push @walks, scalar grep $_, map $grid[rand @grid], 1 .. $steps; } push @contaminated_walks, scalar grep $_, @walks; } my $stat = Statistics::Descriptive::Sparse->new(); $stat->add_data(@contaminated_walks); printf "mean: %.f std. deviation: %.f count: %d\n", $stat->mean, $stat->standard_deviation, $stat->count; __END__ C:\Old_Data\perlp>perl my_stat.pl mean: 64 std. deviation: 5 count: 100