#!/usr/bin/perl ################################################################### # Script to do some statistics (creating bell curves for JD's RPG) ################################################################### $iterations = 1000000; # How many rolls do we make? $dicemax = 6; # 6=d6, 8=d8, etc. $numdice = 3; # How many dice in the pool? 3 = 3d$dicemax $dicekeep = 2; # How many dice to keep/use? ################################################################### $maxtotal = $dicemax * $dicekeep; # currently unused srand (time ^ $$); for (1..$iterations) { for (1..$numdice) { push(@set, int(rand($dicemax))+1); } @set = reverse sort(@set); # to get the highest dice out front $total = 0; for (0..($dicekeep-1)) { $total = $total + @set[$_]; } push(@alltotals, $total); # $total is the total of the top dice ($dicekeep), usually 2 @set = undef; } foreach $topscore (@alltotals) { $scoreset{$topscore}++; } sub mysort { $a <=> $b; } @keys = sort mysort (keys %scoreset); foreach $key (@keys) { print "$key: $scoreset{$key}\n"; }