# Anydice: for XdY(Z+), what are the odds to get the same numbers on all successful faces for 2 success, 3 success, 4 success

For a count success dice pool system, what is the anydice formula to show the probabilities that the rolled success are all the same number?

example: 6d6(4+), what are the chance to have 2 success with 4,4 or 5,5 or 6,6; to have 3 success with 4,4,4 or 5,5,5 or 6,6,6; to have 4 success with 4,4,4,4 or 5,5,5,5 or 6,6,6,6

The goal is to know the chance for successfull rolls to show the same numbers among the success faces.
An anydice formula would allow me to try many different combinations of dice and success faces.

Here is a thread containing a formula that may or may not help: Anydice: for XdY(Z+), what are the odds for at least doubles in Z+?

### The Binomial distribution gives a fancy and quick answer.

The probability of having the same number on the rolled success is $$P(\text{Having } t \text{ equal numbers}) = \mathcal{B}(t,N,p_1)\cdot\mathcal{B}(t,t,p_2)\cdot N_f$$ where

• $$\t\$$ is the target number of successes
• $$\N\$$ is the number of dice rolled
• $$\p_1\$$ is the probability to have a successfull roll
• $$\p_2\$$ is the probability to get the same number on each face of the successfull roll
• $$\N_f\$$ is the number of "good sides" of the die for having a success.

The Python code below implements the above reasoning.

import numpy as np
from scipy.stats import binom

# Number of rolls
N = 6;
# Type of dice
D = 6;
# Success Threshold
sT = 4;

for nSucc in np.arange(1,D+1):
probability = binom.pmf(nSucc,N,(D-sT+1)/D)*(D-sT+1)*binom.pmf(nSucc,nSucc,1/(D-sT+1))
print('Chances to get %d equal numbers on a %d d%d roll: %2.2f%s'%(nSucc,N,D,probability*100,'%'))


### Mathematical explanation.

The binomial distribution of parameters $$\(N,p)\$$ computes the probability of successes in $$\N\$$ trials, assuming a probability $$\p\$$ for success. Let's use the following notation: $$\mathcal{B}(m,N,p)$$ which denotes the probability to get $$\m\$$ success on $$\N\$$ trials, having a probability $$\p\$$ of success.

Let's compute the probability to get a successful roll on a 6d6 with 4+: in this case, a useful result on a die is achieved with a probability of 50% (i.e. the chance to get a 4, a 5 or a 6 on a d6). In this case, referring to the formula at the beginning, we have $$\N=6,\, p_1=0.5\$$.

Let's focus on the case in which one needs two 4+ on a 6d6 ($$\t=2\$$): the probability of having two equal numbers given a successful roll is $$P(\text{two equal numbers}|\text{successful roll}) = P(\text{successful roll})\,P(\text{Having two equal numbers}).$$

The binomial distribution tells us that getting 2 successes on a 6d6 has a probability of $$P(\text{successful roll}) = \mathcal{B}(2,6,0.5)=23.44\%.$$

Since we know that we have exactly 2 dice which are successful, we have to compute the chance to have the same number on each die: $$\begin{split} P(\text{Having two equal numbers}) = &P(\text{two 4s}) + P(\text{two 5s}) + P(\text{two 6s}) \\ =&\frac13\frac13+\frac13\frac13+\frac13\frac13 = 3\frac19 \\ = & \frac13 = 33.33\% \end{split}$$

or, since we are counting to have exactly two successes on two trials with probability 1/3, $$P(\text{Having two equal numbers}) = 3\,\mathcal{B}(2,2,1/3) = 33.33\%$$

and referring again to the formula at the beginning, it means that $$\p_2=1/3\$$, $$\N_f=3\$$.

Then, the final probability is given by $$P(\text{two equal numbers}|\text{successful roll}) = 23.44\%\,33.33\% = 7.81\%$$

according to the answers by posita and SomeoneEvil.

When the number of successes is 3, then $$P(\text{3 equal numbers}|\text{successful roll}) = \mathcal{B}(3,6,0.5)\mathcal{B}(3,3,1/3) = 3.47\%.$$

When we want to look at multiple things in the same dice throw, it's necessary to pass that pool into a function as a sequence. That means that we can use that sequence as though it is a result of an actual throw. When we pass dice to a sequence like that, Anydice will go through every possible result and run our function for it.

By default, Anydice will sort the results in decending order. This lets us be slightly clever, and recognize that the first will always be one of the successes (if any). So, we can compare the count of numbers equal to the first, and if that matches the total count of successes, all the successes are the same. We then just return that count. If they don't match, we return a 0.

function: number of equal successes of SUC:s in POOL:s {
if [count 1@POOL in POOL] = [count SUC in POOL]
{
result: [count 1@POOL in POOL]
}
else { result:0 }
}

output [number of equal successes of {4, 5, 6} in 6d6]


You can find that code here which generates: • There is something that puzzles me: is the prob to get 2 success (two 4s, two 5s or two 6s) on a 6d6 roll 7.81%? I am misreading the results table? May 30, 2022 at 7:47
• @Eddymage I don't think you are, though what might be throwing off any intuition is that it is the probability for exactly two successes which are equal. Meaning there are a lot of results of 6d6 which have successes, but which aren't valid for this specific condition (and all lumped into the 0 result). May 30, 2022 at 10:20
• @Someone_Evil It seems to much low as a probability to me, my simulations tell me a much higher probability. I'll check them. May 30, 2022 at 10:49
• @Someone_Evil Maybe I understood: you (and @posita) are computing the probability of having the same number of a successful roll on the number of possible successes, not on the entire 6d6 roll, it is a conditioned probability. I read the question as "compute the probability of having the same number on a success", i.e. compute the prob of having (two 4s) OR (two 5s) OR (two 6s) on a 6d6. May 30, 2022 at 12:02

This is a dyce¹-based solution, not an AnyDice-based solution, but I believe is otherwise directly responsive. If I understand the call of the question correctly, it asks for a generalized solution to compute the likelihood of certain success counts where those successes are uniform (i.e., all derive from the same outcome). Intuitively, one would expect the frequency that this was zero (or even one) over all possible rolls to be quite high, especially with more faces, more faces eligible as successes, and more dice in the pool. This solution seems to support that intuition:

from collections import Counter
from dyce import H, P
from dyce.p import RollT

def uniform_successes(pool: P, success_threshold: int) -> H:

def _calc(roll: RollT) -> int:
success_outcome_counts = Counter(
outcome for outcome in roll if outcome >= success_threshold
)
if len(success_outcome_counts) == 1:
# The number of distinct outcomes that make up our successes is one (i.e.,
# they are uniform), so grab the count, which is the total number of
# successes
outcome, count = success_outcome_counts.most_common(1)
return count
else:
# Our successes are mixed (or we had none), so we don't count them
return 0

return P.foreach(_calc, roll=pool)

X = 6
Y = 6
Z = 4

print(uniform_successes(pool=X @ P(Y), success_threshold=Z).format(scaled=True))


Output:

avg |    0.40
std |    0.86
var |    0.73
0 |  78.35% |#################################################
1 |   9.38% |#####
2 |   7.81% |####
3 |   3.47% |##
4 |   0.87% |
5 |   0.12% |
6 |   0.01% |


The above focuses on readability, rather than efficiency. There are certainly optimizations to be had (like those @Ilmari Karonen is famous for).

You can play around with a more generalized version in your browser: [source]

While a matter of taste, I find anydyce's² "burst" graphs are well-suited to visualizing distributions for this exploration. (Screenshot of select X, Y, and Z values below.)

¹ dyce is my Python dice probability library.

² anydyce is my visualization layer for dyce meant as a rough stand-in for AnyDice. • awesome... thank you @posita I appreciate it a lot
– user77001
May 26, 2022 at 0:05
• Maybe I am misinterpreting the table: are you saying the probability to get two 4s or two 5s or two 6s on a 6d6 roll is 7.81%? May 30, 2022 at 7:21
• Not quite. It's the probability of getting exactly two fours, two fives, or two sixes and that all other dice in the roll show no value greater than three. In other words, (1, 2, 2, 3, 4, 4) and (1, 1, 3, 3, 5, 5) would be counted, but (1, 2, 2, 4, 4, 5) would not. May 30, 2022 at 22:57
• Oh, well, shame on me... May 31, 2022 at 7:00
• Oh no! No shame in this game! 😊 This tripped me up at first as well. May 31, 2022 at 16:47