#!/usr/bin/perl -w use strict; my $counts = 6; my @numbers; for my $i (0..$counts-2) { if ($i == 0) { $numbers[$i] = int(rand(100)); } else { my $subtotal = 0; $subtotal += $_ for @numbers; $numbers[$i] = int(rand(100-$subtotal)); } } my $amount = 0; print join('+', @numbers) .'+'; $amount += $_ for @numbers; my $last_nr = (100-$amount); print "$last_nr = "; print $amount+$last_nr;