owen

I just realized something interesting about rolling dice online. Forgive my geek side for showing for a moment.

I’ve been messing with modules for JibbyBot (a phenny bot for IRC), trying to pick up a little Python here and there, and something I thought to possibly implement is a dice-rolling module that would let you specify die-rolls in D&D format. I suppose a brief tutorial is in order.

In Dungeons and Dragons (D&D), there are several different polyhedral dice. When the game wants you to roll a specific die, it will specify the number of sides on the die to roll. So for the frequent opportunity you get to roll a 20-sided die, the game will specify this with a shorthand syntax, “d20”, which is really short for “1d20”, meaning to roll the 20-sided die one time. If the game needs you to roll a 6-sided die three times, the shorthand would look like “3d6”. There are also things that let you add or subtract a constant value from the roll, like in “3d6+2”, but that’s not quite relevant for the interesting thought I have come across.

3d6 is a pretty standard roll in D&D. It (or a very similar variation) is used when you create a new character for each of the six stats that represent that character’s abilities. This roll has a certain mathematical property in that the range of numbers is between 3 (the total of dice all rolling 1) and 18 (the total of three dice all rolling 6). When producing characters in the past via automated random number generators, I would simply generate a random number between 3 and 18 and call it a day. As it turns out, this is not an accurate representation of 3d6.

The tricky bit is that 3d6 will result in a more interesting pattern over time. If you roll a lot of 3d6 results with real dice, you’ll note that there is a bell-shaped curve to the results. The numbers 10 and 11 are far more common than 3 or 18. This is because there is only one way to roll the dice and get 1-1-1 for a total of 3, but there are three ways to roll the dice to get 4 (1-1-2, 1-2-1, and 2-1-1). The numbers 10 and 11 have the most possible combinations of values, so they appear more often over time.

So if you’re creating a random number generator that simulates rolling dice, you need to factor in that probability to your results, or you’re going to be very disappointed. 1d15+3 will definitely not yield the same results as 3d6 over many successive rolls.

I’m sure this math is pretty obvious, but it’s something that I had not thought about before, and yet was curious about it when I saw that there are die rollers that still go through iterations of rolls to simulate this curve rather than just picking a flat number at random from within the range. Interesting. I wonder if there’s an easy mathematical way to simulate the curve without doing iterations.