#Produces specified number of six-side die roll results #then produces a frequency distribution for calculating combat results use strict; use Statistics::Descriptive; my $stat = Statistics::Descriptive::Full->new(); print "How many dice do you want to roll(N)?"; my $dicenum = <STDIN>; my @dicearray; for (my $i = 0; $i < $dicenum; $i++) { $dicearray[$i] = (int(rand(6)) + 1); my $roll = $i+1; print "Roll ".$roll." result is: ".$dicearray[$i]; print "\n"; } print "\n"; sleep 3; my @bins = (1,2,3,4,5,6); $stat->add_data(\@dicearray); my %f = $stat->frequency_distribution(\@bins); for (sort {$a <=> $b} keys %f) { print "Result = $_, count = $f{$_}\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Six-side dice roll calculator
by CountZero (Bishop) on Jul 19, 2007 at 19:54 UTC | |
|
Re: Six-side dice roll calculator
by MonkE (Hermit) on Jul 19, 2007 at 22:46 UTC | |
by Scott7477 (Chaplain) on Jul 20, 2007 at 13:23 UTC | |
by CountZero (Bishop) on Jul 20, 2007 at 06:30 UTC | |
|
Re: Six-side dice roll calculator
by rpanman (Scribe) on Jul 20, 2007 at 10:21 UTC | |
|
Re: Six-side dice roll calculator
by Tux (Canon) on Jul 20, 2007 at 07:28 UTC | |
|
Re: Six-side dice roll calculator
by zentara (Cardinal) on Jul 20, 2007 at 11:39 UTC | |
|
Re: Six-side dice roll calculator
by goibhniu (Hermit) on Aug 22, 2007 at 18:08 UTC |