use strict; use warnings; my $min = 10; my $max = 100; my $tests = 10000; my (%c, $n, $average, $deviations); for (1..$tests) { $n = makerandom($min, $max); $c{$n}++; } $average = $tests / ($max - $min + 1); for (sort {$a <=> $b} keys %c) { $n = $c{$_}; $deviations += abs($n - $average); print "$_ => $n\n"; } print "Average deviation +-" . $deviations / ($max - $min + 1) / $average * 100 . " % from $tests tests"; sub makerandom { my ($min, $max) = @_; return int rand ($max - $min + 1) + $min; }