FUNDAMENTALS OF GAME DESIGN, SECOND EDITION
Uniform Distribution
When a computer generates a random number, it ordinarily does so with a uniform distribution. That means the chance of getting any one number exactly equals the chance of getting any other number. It's like rolling a single die: There's an equal chance that a die will land on any one of its faces. That is exactly the behavior you will want whenever you ask the computer to choose among a certain number of equally probable options. For example, if you specify that four possible answers in a multiple-choice quiz game should be presented to the player in a random order, you'll want the possibilities to be mixed up so that each answer has an equal chance of being presented first, second, third, or fourth.
You can create a uniformly distributed die roll value with the following formula (and by discarding any digits after the decimal point in the result):
Die Roll = (Random number x Number of faces on the die) + 1
In other circumstances, you may not want the random values to be evenly distributed but may instead want some values to occur frequently and others to occur only rarely. Suppose you're designing a game about Olympic archery. The player will compete against an artificial opponent, and you want to use a random number to decide where the artificial opponent's arrow lands. At the Olympics, the chances that an archer will hit the bull's-eye are pretty high. The chances that he'll miss the target entirely are extremely low. In specifying where the arrow lands, you won't want it to be uniformly distributed across the target, you'll want it to have a better chance of landing in the middle than anywhere else.
One of the simplest ways to achieve this result is to generate more than one uniformly distributed random number (that is, roll several dice) and add the resulting numbers together to give you a value. This does not yield a uniform distribution of values; the values tend to cluster around a central point, with few values at the extremes.
Here's an example. We all know that if you roll two six-sided dice and add them together, the chance of rolling a 7 is much higher than the chance of rolling a 2 or a 12. But how much higher? As you design the core mechanics of your game, this is something you need to know.
Rolling two six-sided dice and adding the results can produce any of 11 possible values, from 2 (two 1s) to 12 (two 6s). Of 36 possible combinations of two six-sided dice, only one combination yields a 2: throwing two 1s. On the other hand, there are six possible ways to get a 7: 1 + 6, 2 + 5, 3 + 4, 4 + 3, 5 + 2, and 6 + 1. So when you roll two six-sided dice, you're six times as likely to roll a 7 as you are to roll a 2.
The rules of Dungeons & Dragons specify that certain types of random numbers must be generated by rolling three six-sided dice and adding them together. With three dice, the chances are even higher that the result will be somewhere in the
middle. There are 216 possible combinations, producing 12 possible values from 3 (1 + 1 + 1) to 18 (6 + 6 + 6). There are 27 ways to throw a 10 or an 11, but again, only one way to throw a 3 or an 18. In other words, you're 27 times as likely to roll a 10 as you are an 18.