I have a very similar question to Using AnyDice to determine the odds of getting a specific number sequence on multiple dice
I want to know the odds of rolling a 1,2,3 out of 4d6. Or getting a 3 and a 4 on 2d6 vs the same 2 results out of 3d6.
anydicestatistics
I have a very similar question to Using AnyDice to determine the odds of getting a specific number sequence on multiple dice
I want to know the odds of rolling a 1,2,3 out of 4d6. Or getting a 3 and a 4 on 2d6 vs the same 2 results out of 3d6.
Here's the link to the program, and here it is in its entirety:
DICE:{4,6,8,10,12,20}
loop D over {1..(#DICE-1)}{
loop SECOND over {0..5}{
FIRST: 6-SECOND
FIRSTD: D@DICE
SECONDD: (D+1)@DICE
output [count {4..20} in FIRSTdFIRSTD] + [count {4..20} in SECONDdSECONDD] named "[FIRST]d[FIRSTD] and [SECOND]d[SECONDD]"
}
}
It is, in fact, possible to do this with AnyDice:
function: compare A:s and B:s {
result: A = B
}
output [compare 4d6 and {5, 2, 2, 1}]
The trick here is that, when passing a die (like 4d6
here) to a function expecting a sequence, AnyDice will call the function for every possible (sorted) roll of the dice, and return a distribution (i.e. a biased die) giving the probability of obtaining each result.
(Note that the literal sequence {5, 2, 2, 1}
needs to be sorted from highest to lowest value, since that's AnyDice's default sorting order for dice rolls.)
Running the above program gives about 0.93% for the probability to roll [1, 2, 2, 5], in any order, on 4d6. To double-check the result, we can calculate the probability by hand, and compare it to the AnyDice result:
The first thing to realize is that, as long as our dice are fair, the actual numbers in the sequence are irrelevant: we would get the exact same probability for rolling [1, 2, 2, 3] or [2, 5, 5, 6], or even [4, 5, 6, 6]. All that matter is the fact that there are four dice, each with six sides, and that we're interested in the probability of rolling a specific combination, where two of the rolls are equal, in any order. Below, I will keep using [1, 2, 2, 5] as an example, but it's important to keep in mind that we would get the same result for any such set of rolls.
The rest is simple combinatorics:
There are 64 = 1296 possible (and equally likely) results of rolling 4 six-sided dice in sequence. We want to know how many of those sequences, when sorted, yield [1, 2, 2, 5].
There are 4! = 4 × 3 × 2 × 1 = 24 ways to shuffle a set of four distinct numbers: we can put the smallest number in any of the four positions, then the next-smallest in any of the three remaining ones, and so on. Thus, if all the numbers in the combination we wanted were distinct, there would be 4! = 24 ways to roll it, and thus the probability of rolling it would be 4! / 64 = 24 / 1296 = 1/54 ≈ 1.85%.
However, in the set [1, 2, 2, 5], two of the numbers are equal. What to do? Well, let's pretend for a moment that the numbers are actually, say, [1, 2a, 2b, 5], where the labels "a" and "b" have been added to make the two "2"s distinct.
Now we have four distinct items, which we can shuffle in 4! = 24 different ways. If we then drop the extra labels we added to the numbers to make them distinct, we get an arrangement of the original numbers: for example, [5, 2a, 1, 2b], with the labels removed, gives us [5, 2, 1, 2]. But so does [5, 2b, 1, 2a]! In fact, for every arrangement of [1, 2, 2, 5], there are two arrangements of [1, 2a, 2b, 5] that yield it when the labels are removed: one that has 2a before 2b, and one that has them the other way around.
Thus, if two of the numbers in our set are equal, then there are only 24 / 2 = 12 ways to shuffle it, and thus only 12 of the 1296 possible sequences of 4d6 will yield it when sorted. Thus, the probability of rolling [1, 2, 2, 5] on 4d6, in any order, is 12 / 1296 = 1/108 ≈ 0.93%, just as AnyDice told us.
We can apply the same reasoning for sets with more duplication. For example, in the set [1, 1, 5, 5], we have two pairs of equal numbers. We can use the same trick of labeling them as [1a, 1b, 5a, 5b] before shuffling them, but now each unlabeled sequence corresponds to 2 × 2 = 4 labeled sequences. Thus, the number of ways to roll [1, 1, 5, 5] on 4d6, in any order, is 24 / 4 = 6, and thus the probability or rolling it is 6 / 1296 = 1/216 ≈ 0.46%.
What about the case of three equal numbers, as in [1, 2, 2, 2]? Again, we can relabel the numbers as [1, 2a, 2b, 2c], and have 24 ways of shuffling them, but now there are more than two ways to arrange the "2"s. How many more? Well, the answer is given by the same formula we used to count the total number of arrangements above: the number of ways to sort three distinct items (here, [2a, 2b, 2c]) is 3! = 3 × 2 × 1 = 6. Thus, there are only 24 / 6 = 4 ways to arrange the unlabeled set [1, 2, 2, 2] — a fact which is easily verifiable by hand — and thus the probability of rolling it is 4 / 1296 = 1/324 ≈ 0.31%.
Finally, of course, for four equal numbers, as in [1, 1, 1, 1], there's clearly just one way to roll them, and the probability is thus 1/1296 ≈ 0.077%.
Here's the same information, conveniently tabulated:
Probability of rolling a specific set of numbers on 4d6, in any order:
All numbers distinct: 24 / 1296 = 1/54 ≈ 1.85%
Two numbers equal: 12 / 1296 = 1/108 ≈ 0.93%
Two equal pairs: 6 / 1296 = 1/216 ≈ 0.46%
Three numbers equal: 4 / 1296 = 1/324 ≈ 0.31%
Four numbers equal: 1 / 1296 ≈ 0.077%
You can use the same method to work out similar probabilities for any number of dice of any kind. For example, the number of distinct ways to shuffle the set [2, 2, 3, 3, 3] is 5! / (2! × 3!) = 120 / (2 × 6) = 10, while the total number of ways to roll 5d6 in sequence is 65 = 7776, giving a probability of 10 / 7776 ≈ 0.13% of rolling that combination, in any order, on 5d6.
(And yes, this method is equivalent to the multinomial coefficients suggested by limsup; by definition, Multinomial(n1, n2, ..., nk) = (n1 + n2 + ... + nk)! / (n1! × n2! × ... × nk!).)
Ps. In the answer above, I assumed that you were interested in the probability of rolling a specific set of number in any order, so that e.g. [1, 2, 5, 2] and [1, 2, 2, 5] would be considered equivalent outcomes, but [2, 3, 3, 6] would be considered a different outcome.
If you instead want the combined probability of rolling any combination that contains exactly one pair of equal numbers, whatever those numbers are, you'll need to multiply the probability of rolling any one of those combinations (calculated above) with the total number of such combinations.
How many such combinations are there? There are several ways to calculate that, but a fairly simple one is to:
First count the number of ways to choose three distinct numbers (in any order) out of the six on the die: that's such a common thing to do in combinatorics that there's a special notation for it: 6C3, read as "6 choose 3". (There's a more common notation that's written sort of like "(63)", but with the 6 directly above the 3; alas, I can't type it properly here.) This number can most easily be calculated as the number of ways to choose three distinct items out of six in order, i.e. 6 × 5 × 4 = 6! / (6−3)!, divided by the number of ways to shuffle the chosen items, i.e. 3 × 2 × 1 = 3!, which yields 6C3 = (6! / (6−3)!) / 3! = 120 / 6 = 20.
Next, multiply this number by three, to account for the fact that we can choose any one of the three numbers to be doubled. Thus, the total number of combinations of four numbers between 1 and 6, with exactly one pair of the numbers equal, is 6C3 × 3 = 60, and thus the probability of rolling such a combination on 4d6 is 60 × 12 / 1296 = 60 / 108 ≈ 55.6%.
Similarly, the number of combinations of four distinct numbers between 1 and 6 can be calculated as 6C4 = (6! / (6−4)!) / 4! = (6 × 5 × 4 × 3) / (4 × 3 × 2 × 1) = 360 / 24 = 15, giving a total probability of 15 × 24 / 1296 ≈ 27.8% of rolling four different numbers with 4d6. (Note that this is less than the probability of rolling a single pair, even though each of the four-different combinations is individually more probable than the one-pair combinations, simply because there are fewer combinations where all the dice are different than ones where two are the same.)
For two pairs, we get 6C2 = 15 possible combinations (since we need to choose two numbers out of six, and they're both doubled so we don't need to make any additional choices about that), for a total probability of 15 × 6 / 1296 ≈ 6.94%. (It's not a coincidence that 6C2 = 6C4; a moment of thought should make it obvious that choosing two items out of six is equivalent to choosing four and leaving two behind.) For three of a kind, the number of combinations is 6C2 × 2 = 30 (we choose two distinct numbers, and triple one of them), and so the total probability is 30 × 4 / 1296 ≈ 9.26%, while for four of a kind, we have just 6C1 = 6 choices, for a total probability of 0.46%. Or,in tabular format:
Probability of rolling any result with a given pattern of equal/distinct numbers with 4d6, in any order:
All numbers distinct: 15 × 24 / 1296 ≈ 27.78%
Two numbers equal: 60 × 12 / 1296 ≈ 55.56%
Two equal pairs: 15 × 6 / 1296 ≈ 6.94%
Three numbers equal: 30 × 4 / 1296 ≈ 9.26%
Four numbers equal: 6 × 1 / 1296 ≈ 0.46%
Pps. Yes, we can do this in AnyDice, too, but it's a bit more complex. Here's an example for various outcomes of rolling 4d6:
function: unique values in S:s {
U: {}
loop N over S { if !(N = U) { U: {U, N} } }
result: U
}
function: find PATTERN:s in ROLL:s {
COUNTS: {}
loop N over [unique values in ROLL] {
COUNTS: {COUNTS, N = ROLL}
}
result: [sort PATTERN] = [sort COUNTS]
}
output [find {4} in 4d6] named "four of a kind"
output [find {3, 1} in 4d6] named "one triple, one single"
output [find {2, 2} in 4d6] named "two pairs"
output [find {2, 1, 1} in 4d6] named "one pair, two singles"
output [find {1, 1, 1, 1} in 4d6] named "all singles"
Look at the graph labeled "1" in the Transposed view to see all the probabilities nicely in a single bar graph.
Best Answer
We'll pretend we have
k
s
-sided dice and we are trying to find the probability to getn
specific different results. The first die roll we have ann/s
chance of getting a number we need and an(s-n)/s
chance we get a number we don't need. When we get a number we need we are looking to getn-1
numbers we need onk-1
different dice. When we get a number we don't need we are still looking to getn
numbers but withk-1
dice left to roll. The probability of gettingn = 0
results is always1
regardless of the number of dice. The probability of getting any more results when there aren't any dice left (k = 0
) is0
.We can make a table to calculate these for
s = 6
sided dice.The problems you are interested in are getting
n=2
specific different results withk=2
dice which has a probability of2/36
, gettingn=2
specific different results withk=3
dice, which has a probability of30/216
, and gettingn=3
specific different results withk=4
dice, which has a probability of108/1296
.There is probably a simpler non-recursive formula based on the factorial function.
We can check the above formula with counting arguments.
To get a 3 and a 4 rolling
2d6
there's1
combination of dice that will work. We don't care if we roll the 3 first or the 4 first, so there are2! = 2*1 = 2
orders we can roll the combination in.2
of the6^2
possible rolls result in a 3 and a 4. The probability of rolling a 3 and a 4 on2d6
is2/36
or1/18
.We can make a table of all the ways to roll a 3 and a 4 on
2
dice and count them to make sure this is correct2
ways out of36
roll a 3 and a 4.There are more ways to roll a 3 and a 4 than there are ways to roll two 3s. Theres' only one way to roll two 3s. If we switch the order we roll the dice in it doesn't add another way to get two 3s. This will matter when we add extra dice.
Let's write down all the ways we can roll a 3 and a 4 on
3d6
. We'll use*
to denote any result that is neither a 3 or a 4 (there are4
possible such results: 1, 2, 5, and 6)When one of the results isn't a 3 or 4 it's easy, there's
4
combinations that can be in3! = 3*2*1 = 6
orders. When all of the results have a 3 or 4 then one of the numbers will be repeated. Instead of having2
combinations that can be in3! = 3*2*1 = 6
, half of the orders are duplicates, so there are only30=6*4+2*3
ways to roll a 3 and a 4. The probability of rolling a 3 and a 4 on3d6
is therefore30/6^3
or5/36
.Counting results to check larger problems is tedious. This line of thinking is leading to a recursive formula involving factorial which is no simpler than the recursive formula we started with.