#!/usr/bin/perl use strict; my ($MIN, $MAX, $NUM, $AVERAGE) = qw(0 100 64 32); my $small = $AVERAGE - $MIN; my $large = $MAX - $AVERAGE; my ($i, $rand, $total, $actual); for ($i = 1; $i <= $NUM; $i++) { if ($actual < $AVERAGE) { $rand = int(rand($large) + $AVERAGE); } else { $rand = int(rand($small) + $MIN); } $total += $rand; $actual = $total / $i; print "$rand $actual\n"; }