my @weights = qw(0.5 1 2); my @random = sort {$a <=> $b} map{rand()} 0..$#weights; my $tot; foreach (0..$#weights) { $tot += $random[$_] * $weights[$_]; } print $tot;