Obviously, you roll 1.5 dice. Or 1.2 dice. The sub below allows you to roll any positive number (*) of dice. I've included a little wrapper program so you can see the distribution of results of 50000 throws.
The parameters are, in order: lowest value to return (integer), number of distinct possible return values (integer), how many dice to use.
* numbers smaller than 1 all act like 1
my $range=12; my $low_end=6; my $dice=1.2; my %freq = (); for (1..50000) { $freq{ roll_dice($low_end, $range, $dice) }++ } print "$_: $freq{$_}\n" for sort {$a<=>$b} keys %freq; sub roll_dice { my ($low_end, $range, $dice) = @_; my $result = 0; my $i; for ($i = $dice; $i >=1; --$i) { $result += rand($range); } $result += rand($range) * $i; int($low_end) + int($result/$dice); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Fractional dice (more not fewer)
by tye (Sage) on Jan 30, 2004 at 03:07 UTC | |
by jweed (Chaplain) on Jan 30, 2004 at 03:41 UTC | |
by tye (Sage) on Jan 30, 2004 at 03:54 UTC | |
by jweed (Chaplain) on Jan 30, 2004 at 03:56 UTC | |
by tye (Sage) on Jan 30, 2004 at 04:09 UTC | |
by Roy Johnson (Monsignor) on Jan 30, 2004 at 16:10 UTC | |
by tye (Sage) on Jan 30, 2004 at 16:35 UTC | |
by Roy Johnson (Monsignor) on Jan 30, 2004 at 18:45 UTC |