# Dice Distributions

To generate random numbers that follow a certain distribution you can generate them using the formula of the distribution. This is great if you have a distribution which is in polynomial form. Another way to get such a distribution is to make use of dice.

I know what the distribution of 2 dice with 6 sides looks like, commonly expressed in the form 2D6. It gives a normal distribution over the range 2 to 12 with 7 being the most frequent. The original method I wrote did just this. This meant that I could generate values that followed a normal distribution. Shifting the distribution was done simply by offsetting the value returned with some other value.

What I did not know was how the distribution looked if I started applying bonuses to the rolls or if I started removing the highest or weakest rolls. An article at Red Blob Games discusses damage rolls in D&D style systems and I decided to use it as a base for modifying the original dice method to cater for skewing of the distribution (e.g. removal of dice) and offsetting the distribution of 6D12 by 2 for instance, commonly expressed 6D12 + 2.

The demo in this post makes use of the below method to generate distributions. The inputs can be modified and the effect that they have on the distribution can be seen. This ends up being quite an effective way to express and control a distribution which can be used for damage rolls, attributes rolls and basically any value that needs to vary around a frequent point.

# Notes

• Removing the lowest roll skews the distribution to the right.
• Removing the highest roll skews the distribution to the left.
• Adding or removing successful criticals skews the distribution.
• Adding or removing successful criticals  can be used to generate a local maxima.
• Use asymmetry to make higher-than-average or lower-than-average values occur more often.
• Attribute rolls often make higher than average values more common.
• Damage rolls often make lower than average values more common.
• Low number of rolls has high variance whereas high number of rolls has low variance.
• Bonuses offset the distribution.
• Die size controls the scale of the distribution.
• Positive offsets can be used for bonus damage or attributes; negative offsets can be used for blocking damage.

# Code Snippet

```package net.avdw.stats
{

public function rollDice(numDice:int = 2, numSides:int = 6, bonus:int = 0, highThrowsToRemove:int = 0, lowThrowsToRemove:int = 0):Number
{
var i:int;
var rolls:Array = [];

for (i = 0; i < numDice; i++)
rolls.push(Math.floor(Math.random() * numSides));

rolls.sort(Array.NUMERIC);
rolls.splice(0, lowThrowsToRemove);
rolls.splice(rolls.length - highThrowsToRemove);

var value:int = 0;
for (i = 0; i < rolls.length; i++)
value += rolls[i];

return value + bonus;
}

}```
• Pingback: Triangle from a Stick (Monte Carlo)()

• Pingback: Streaming Histograph()

• jwvanderbeck

Your code for the individual dice seems to be incorrect. It is treating a die as a range from 0 to Sides-1, rather than 1 to Sides. Which means when you roll multiple dice the min/max numbers are off. For example 3D6 with no other bonuses or anything is showing a min 0 max 15 instead of min 3 max 18 like it should.