in reply to Re^3: Fractional dice (buckets)
in thread Fractional dice
It's more likely the result of rounding slop on my part than it is an artifact of using random numbers. No such effects are seen when the function is this straightforward 2-dice method:
And here's dice-rolling code generalized to let you choose a range and number of dice, and it will figure how many sides each die needs. (No fractional dice, here.)sub roll_dice { my ($low_end, $range) = @_; int(rand(int $range/2)) + int(rand(1 + $range - int $range/2)) + $lo +w_end; }
sub roll_dice { my ($low_end, $range, $dice) = @_; my $sidesneeded = $range + $dice - 1; my $r = 0; for (0..$dice-1) { my $sides = int($sidesneeded / ($dice-$_)); $sidesneeded -= $sides; $r += int(rand $sides); } $low_end + $r; }
|
|---|