#!/usr/bin/perl -w use strict; my ($counter, $tests) = (0, 100_000_000); my %results; my $rand; #declare once, save time while ($counter++ < $tests) { #not creating with .. operator, mem efficient $rand = int(rand(10) + 1); $results{$rand}++; } my $total; $total += $_ for values %results; #only 10 results possible print "\n\n"; print "Total\t$total\n\n"; print "$_:\t$results{$_}\t\t" . $results{$_} / $total * 100 . "\n" for sort {$a <=> $b} keys %results; print "\n\n";