What is the probability of rolling a 12 with two dice

What is the probability of rolling a 12 with two dice
Performing probability questions in kdb/q is simple. I recently got asked how to find the probability of rolling a sum of 12 with two dice. We’ll look at two approaches to finding the likely outcomes in kdb/q:

Method 1 – Enumeration of all possibilities

Step by step we:

  1. Generate the possible outcomes for one die.
  2. Generate all permutations for possible outcomes of two dice, find the sum of the dice.
  3. Count the number of times each sum occurs and divide by all possible outcomes to get each probability.
q)1+til 6 / all possible outcomes of one die 1 2 3 4 5 6 q)a cross a:1+til 6 / all possible outcomes of two dice 1 1 1 2 1 3 1 4 1 5 1 6 2 1 .. q)sum each a cross a:1+til 6 / the sums 2 3 4 5 6 7 3 4 5 6 7 8 4 5 6 7 8 9 5 6 7 8 9 10 6 7 8 9 10 11 7 8 9 10 11 12 q)group sum each a cross a:1+til 6 / group the occurrence of each sum 2 | ,0 3 | 1 6 4 | 2 7 12 5 | 3 8 13 18 6 | 4 9 14 19 24 7 | 5 10 15 20 25 30 8 | 11 16 21 26 31 9 | 17 22 27 32 10| 23 28 33 11| 29 34 12| ,35 q){x%sum x} count each group sum each a cross a:1+til 6 / tidy our output to give probability 2 | 0.02777778 3 | 0.05555556 4 | 0.08333333 5 | 0.1111111 6 | 0.1388889 7 | 0.1666667 8 | 0.1388889 9 | 0.1111111 10| 0.08333333 11| 0.05555556 12| 0.02777778

Method 2 – Monte Carlo Simulation

Alternatively , if it hadn’t occurred to us to use cross to generate all possible outcomes, or for situations where there may be too many to consider. We can use Monte Carlo method to simulate random outcomes and then similarly group and count their probability.

q)1+900000?/:6 6 / random pairs of dice rolls 2 5 6 6 2 4 3 1 5 1 1 4 6 5 3 4 2 4 1 2 3 6 6 1 1 3 6 3 6 2 3 1 5 4 4 4 6 3 1 3 1 2 5.. 4 4 4 5 1 4 3 6 5 1 4 4 3 4 1 1 1 5 4 5 2 4 4 4 5 2 1 2 6 5 2 4 3 1 4 2 1 1 3 4 6 5 1.. q)/ same as before, count frequency of each result q)(2+til 11)#{x%sum x} count each group sum each flip 1+900000?/:6 6 2 | 0.02766 3 | 0.05559 4 | 0.08347 5 | 0.11085 6 | 0.1391822 7 | 0.1669078 8 | 0.1386156 9 | 0.1112589 10| 0.08317222 11| 0.05556222 12| 0.02773111

Therefore the probability of rolling a sum of 12 with two dice is 1/36 or 0.27777. Here’s the similar dice permutation problem performed in java.

Kdb Problem Questions

If you want to try using the monte carlo method yourself try answering these questions:

  1. The Birthday Paradox: How many people do you need before the odds are good (greater than 50%) that at least two of them share a birthday?
  2. Finding the value of Pi. Consider a square at the origin of a coordinate system with a side of length 1. Now consider a quarter circle inside of the square, this circle has a radius of 1, therefore its area is pi/4. For a point (X,Y) to be inside of a circle of radius 1, its distance from the origin (X ², Y²) will be less than or equal to 1. We can generate random (X,Y) positions and determine whether each of them are inside of the circle. The ratio of those inside to outside will give the area. (bonus points for using multiple threads)

Well, the question is more complex than it seems at first glance, but you'll soon see that the answer isn't that scary! It's all about maths and statistics.

First of all, we have to determine what kind of dice roll probability we want to find. We can distinguish a few which you can find in this dice probability calculator.

Before we make any calculations, let's define some variables which are used in the formulas. n - the number of dice, s - the number of an individual die faces, p - the probability of rolling any value from a die, and P - the overall probability for the problem. There is a simple relationship - p = 1/s, so the probability of getting 7 on a 10 sided die is twice that of on a 20 sided die.

  1. The probability of rolling the same value on each die - while the chance of getting a particular value on a single die is p, we only need to multiply this probability by itself as many times as the number of dice. In other words, the probability P equals p to the power n, or P = pⁿ = (1/s)ⁿ. If we consider three 20 sided dice, the chance of rolling 15 on each of them is: P = (1/20)³ = 0.000125 (or P = 1.25·10⁻⁴ in scientific notation). And if you are interested in rolling the set of any identical values, simply multiply the result by the total die faces: P = 0.000125 * 20 = 0.0025.

  2. The probability of rolling all the values equal to or higher than y - the problem is similar to the previous one, but this time p is 1/s multiplied by all the possibilities which satisfy the initial condition. For example, let's say we have a regular die and y = 3. We want to rolled value to be either 6, 5, 4, or 3. The variable p is then 4 * 1/6 = 2/3, and the final probability is P = (2/3)ⁿ.

  3. The probability of rolling all the values equal to or lower than y - this option is almost the same as the previous one, but this time we are interested only in numbers which are equal to or lower than our target. If we take identical conditions (s=6, y=3) and apply them in this example, we can see that the values 1, 2, & 3 satisfy the rules, and the probability is: P = (3 * 1/6)ⁿ = (1/2)ⁿ.

  4. The probability of rolling exactly X same values (equal to y) out of the set - imagine you have a set of seven 12 sided dice, and you want to know the chance of getting exactly two 9s. It's somehow different than previously because only a part of the whole set has to match the conditions. This is where the binomial probability comes in handy. The binomial probability formula is:

P(X=r) = nCr * pʳ * (1-p)ⁿ⁻ʳ,

where r is the number of successes, and nCr is the number of combinations (also known as "n choose r").

In our example we have n = 7, p = 1/12, r = 2, nCr = 21, so the final result is: P(X=2) = 21 * (1/12)² * (11/12)⁵ = 0.09439, or P(X=2) = 9.439% as a percentage.

  1. The probability of rolling at least X same values (equal to y) out of the set - the problem is very similar to the prior one, but this time the outcome is the sum of the probabilities for X=2,3,4,5,6,7. Moving to the numbers, we have: P = P(X=2) + P(X=3) + P(X=4) + P(X=5) + P(X=6) + P(X=7) = 0.11006 = 11.006%. As you may expect, the result is a little higher. Sometimes the precise wording of the problem will increase your chances of success.

  2. The probability of rolling an exact sum r out of the set of n s-sided dice - the general formula is pretty complex:

What is the probability of rolling a 12 with two dice

However, we can also try to evaluate this problem by hand. One approach is to find the total number of possible sums. With a pair of regular dice, we can have 2,3,4,5,6,7,8,9,10,11,12, but these results are not equivalent!

Take a look, there is only one way you can obtain 2: 1+1, but for 4 there are three different possibilities: 1+3, 2+2, 3+1, and for 12 there is, once again, only one variant: 6+6. It turns out that 7 is the most likely result with six possibilities: 1+6, 2+5, 3+4, 4+3, 5+2, 6+1. The number of permutations with repetitions in this set is 36. We can estimate the probabilities as the ratio of favorable outcomes to all possible outcomes: P(2) = 1/36, P(4) = 3/36 = 1/12, P(12) = 1/36, P(7) = 6/36 = 1/6.

The higher the number of dice, the closer the distribution function of sums gets to the normal distribution. As you may expect, as the number of dice and faces increases, the more time is consumed evaluating the outcome on a sheet of paper. Luckily, this isn't the case for our dice probability calculator!

  1. The probability of rolling a sum out of the set, not lower than X - like the previous problem, we have to find all results which match the initial condition, and divide them by the number of all possibilities. Taking into account a set of three 10 sided dice, we want to obtain a sum at least equal to 27. As we can see, we have to add all permutations for 27, 28, 29, and 30, which are 10, 6, 3, and 1 respectively. In total, there are 20 good outcomes in 1,000 possibilities, so the final probability is: P(X ≥ 27) = 20 / 1,000 = 0.02.

  2. The probability of rolling a sum out of the set, not higher than X - the procedure is precisely the same as for the prior task, but we have to add only sums below or equal to the target. Having the same set of dice as above, what is the chance of rolling at most 26? If you were to do it step by step, it would take ages to obtain the result (to sum all 26 sums). But, if you think about it, we have just worked out the complementary event in the previous problem. The total probability of complementary events is exactly 1, so the probability here is: P(X ≤ 26) = 1 - 0.02 = 0.98.

Use this dice odds calculator to easily calculate any type of dice roll probability: sum of two dice, sum of multiple dice, getting a value greater than or less than on a given throw of N dice, and so on. Different types of dice are supported: from four-sided, six-sided, all the way to 20-sided (D4, D6, D8, D10, D12, and D20) so that success probabilities and dice odds in popular dice games can be computed.

    Quick navigation:

The tool can be used to compute dice probabilities for any type of game of chance or probability problem as used in teaching basic statistical concepts such as sample space and p-values. It supports the classic scenario of computing probabilities of the sum of two six-sided dice, but also supports 4-sided, 8-sided, 10-sided, 12-sided, and 20-sided dice. In the classic problem two dice are thrown, but with this dice calculator you can also explore it with three or more dice.

The calculator can output, depending on the choice of probability calculation, the probability of:

  • throwing an exact sum of two or more dice
  • a sum less than or greater than or equal to a given number
  • at least one die having a face equal to a given number
  • all dice having rolling a value equal to a given number
  • at least one die rolling a value less than or equal, or greater than or equal to a number
  • all dice rolling a value less than or equal, or greater than or equal to a number

With such versatility you can calculate dice probabilities for most games of chance such as Craps, Backgammon, Dungeons & Dragons (D&D), Balut, Dice 10000, Diceball!, Dudo, Elder Sign, Kismet, Yahtzee, Bunco, and many more.

The classic case of exploring dice throw probabilities (dice rolling odds) is to estimate the chance of landing a given sum on the faces of two six-sided dice. In this example, two dice are thrown together and one records their face values, and computes their sum. Each die is a cube with six faces with the numbers from one to six printed on each side. One throws two dice and the value of a roll is whatever number faces up once the die settles in place.

What is the probability of rolling a 12 with two dice

The image above shows six such dice each with a different face up. The question is: what is the probability of rolling a given sum with two six-sided dice?. The dice are assumed to be fair (unbiased), meaning each side has equal probability of turning up. Also, the outcome of each roll is independent of rolls preceding or succeeding it. A series of fair dice rolls can be modelled as independent events.

Sample space of the two dice problem

In essence, one needs to first estimate the size of the set of all possible outcomes of the dice throw known as the sample space, and then figure out how many of these result in the desired sum. To solve this problem, one needs to calculate every possibility which might turn up which amounts to estimating how many possible permutations there are in total.

For two 6-sided dice there are exactly 6^2 = 6 · 6 = 36 possible permutations with repetition (selecting two numbers from a set of six).

Calculating two (6-sided) dice probability

Knowing the sample space means now we need only compute how many possible ways there are for the dice to result in the sum of interest. For example, if the sum of interest is 12, there is just a single dice permutation which results in such a sum - it only happens if both dice thrown roll a six (double sixes, a.k.a. 'boxcars'). The chance to roll a twelve is then 1 out of 36 = 1 / 36 = 0.02777 or 2.77%. It is also the chance of rolling double ones (a.k.a. 'snake eyes').

If the question is what is the chance of throwing a seven with two dice, then one should consider all possible permutations in which a seven turns up. A seven can be the sum of (6 and 1), (5 and 2), (4 and 3) for a total of three possible permutations, and then we need to consider them in the other possible way, namely (1 and 6), (2 and 5), (3 and 4), for a total of six permutations. So we have six chances out of thirty six, meaning the probability of throwing exactly seven is 6/36 = 1/6 = 0.1666 = 16.66%.

Two dice probability chart

Doing the calculations for all possible outcomes between two and twelve for the sum of two dice rolls one arrives at the following chart of dice probabilities and dice odds. It is for two dice rolled simultaneously or one after another (classic 6-sided dice):

What is the probability of rolling a 12 with two dice

If two dice are thrown together, the odds of getting a seven are the highest at 6/36, followed by six and eight with equal odds of 5/36 (13.89%), then five and nine with odds of 4/36 (11.11%), and so on. Here is the same information in table form:

Sum of two (6-sided) dice probabilities
Roll a sum ofProbability (Odds)
2 2.778% (1/36)
3 5.556% (2/36)
4 8.333% (3/36)
5 11.111% (4/36)
6 13.889% (5/36)
7 16.667% (6/36)
8 13.889% (5/36)
9 11.111% (4/36)
10 8.333% (3/36)
11 5.556% (2/36)
12 2.778% (1/36)

    Dice probability formula

The probability (P) of rolling a given sum (p) by throwing any number of dice (n) with a given number of sides or faces (s) can be calculated using the general formula as provided by Uspensky 1937 [1]:

What is the probability of rolling a 12 with two dice

The brackets ⌊ ... ⌋ in the upper limit of the sigma operator denote the floor mathematical function. The round brackets with two numbers one on top of the other denote combinations without repetition. It is read as "n choose k" and its computation uses the factorial function. This makes it somewhat difficult to compute the equation by hand so a dice probability calculator comes in super handy even with a small number of dice.

The formula can be used to produce dice probability distribution charts for any type and number of dice, and dice rolls. With a larger number of dice the distribution converges to the normal distribution in accordance with the Central Limit Theorem [2]. Calculating the probability of rolling greater than or less than a certain sum simply entails summing the probabilities of all possible outcomes greater than the sum of interest.

    Probabilities with a single die roll

The probability of rolling any given number with a single die on a single roll is equal to one divided by the number of die faces. For example, with a 20-sided die, the odds of rolling 20 is 1/20 or a 5% chance. With a classic six-sided die the probability of seeing any particular face is 16.667% or chance odds of 1/6. As you can see, single die roll probabilities require only simple division to calculate.

    Probability of rolling a certain number with n dice throws

If there is more than one throw possible, e.g. if throwing two dice simultaneously or one after another, the probability of rolling a given number with at least one of the throws increases. However, it never reaches 100%! For example, if one needs a six and has six throws of a D6 die, the probability of rolling a six is not 16.667% · 6 = 100%.

A clever way to easily calculate it is to first raise the probability of not getting a six on each throw to the power of the number of throws possible. The probability of not rolling a six is (6-1) / 6 = 5/6 or 0.8333. With six dice, we have 5/6^6 = 5/6 · 5/6 · 5/6 · 5/6 · 5/6 · 5/6 = 0.3349. This means that the probability of throwing at least one six with six tries is 1 - 0.3349 = 0.6651 or 66.51% giving odds of roughly 2/3. In effect, the multiplication in the denominator calculates the sample space whereas the multiplication in the numerator computes the number of unfavourable outcomes in the sample space. We have 5^5 = 15,625 possibilities for not seeing a single six out of 6^6 = 46,656 total possibilities.

Here is a chart of the probabilities of getting at least one six with increasing number of dice rolls:

What is the probability of rolling a 12 with two dice

While the probability increases slowly with each subsequent dice throw, it never actually reaches 100%.

    Probability of rolling a certain number on all n dice

In contrast to the probability of throwing a certain number by having n tries (either throwing n dice together or throwing a die n times), the probability of rolling the same face value on a number of dice decreases substantially the more dice there are. The probability never reaches zero, but it can be considered practically nil after a certain number of dice. Here is a graph with these probabilities:

What is the probability of rolling a 12 with two dice

With just ten dice throws, the probability of rolling a six on all is a mere 0.000002%, and the chance only decreases further when more dice throws are added.

    Examples

Here are a few more examples for the odds in different games with dice.

What are the odds of throwing more than 9 at craps?

Craps is played with two six-sided dice. To calculate the odds of rolling 9 or more we need to use the dice probability formula above and compute the probabilities for all possible outcomes of throwing the two dice: 9, 10, 11, and 12, then sum them up. Using the table above we can see the odds are 4/36, 3/36, 2/36, and 1/36 respectively. Summing them up (you can use our fractions calculator for this task) results in odds of 10/36 (10 to 36), or a probability of 0.2778 (27.78%).

What are the odds of rolling 38 or more in D&D?

Dice play an important role in the tabletop game Dungeons and Dragons (DnD). Sometimes one needs to roll a high number to have a chance at performing a given action such as successfully casting a spell. What is the probability of rolling 38 or more given that one can throw two 20-sided dice? Using the equation for the sum of n dice above, we can compute the probability of getting exactly 38, 39, and 40 to be 0.75%, 0.5%, and 0.25%. Summing these up, we get that the chance to roll 38 or higher in D&D, is 0.75% + 0.5% + 0.25% = 1.5% (or odds of 1 out of 66.7).

[1] Uspensky, J. V. (1937) "Introduction to Mathematical Probability", New York: McGraw-Hill, pp. 23-24

[2] Spanos A. (2019) "Probability Theory and Statistical Inference", Cambridge University Press, pp. 396-404, doi: 10.1017/9781316882825