#!/usr/bin/perl use strict; my @count = (); # the range is 0 to 19 my $max = 20; # how many numbers to generate my $size = 10000; # generate a set of random numbers # and count the frequency for (my $i=0; $i<$size; $i++) { my $n = int(rand($max)); $count[$n]++; } # display the frequencies print "Number\tCount\tPercent\n"; for (my $i=0; $i<$max; $i++) { my $ratio = int(0.5 + 1000 * $count[$i]/$size)/10; print $i . "\t" . $count[$i] . "\t"; printf("%.1f\n",$ratio); }