4
\$\begingroup\$

I would like to draw a graph of this in AnyDice:

  • y-axis: percentage chance of success
  • x-axis: number of D6 dice in the range 1-10
  • series a: success is at least one 4+
  • series b: success is at least one 5+
  • series c: success is at least one 6

I tried but cannot get it to work: https://anydice.com/program/36184

function: roll ROLL:s {
 if [count 6 in ROLL] { result: 6 } \ 6 \
 if [count {5,6} in ROLL] { result: 5 } \ 5+ \
 if [count {4,5,6} in ROLL] { result: 4 } \ 4+ \
}

loop DICE over {1..10} {
 output [roll DICEd6] named "[DICE]d6"
}
\$\endgroup\$
1
  • \$\begingroup\$ Welcome to RPG.SE! Take the tour and have a look at the help center for any guidance in posting in this website. Happy gaming! \$\endgroup\$
    – Eddymage
    Apr 24 at 7:55

2 Answers 2

7
\$\begingroup\$

The no-result issue

The first issue is that your function does not emit any result if no 4+s are rolled. When AnyDice does not receive any result from a function (or if the result is an empty die), it removes that evaluation of the function from the probability space entirely. This can be useful in some situations but is not what you want here, as 100% of rolls will appear to have rolled at least 4+. This is why your 1d6 appears to roll 4, 5, and 6 one-third of the time each. In this case you can modify the function to return a failure value:

function: roll ROLL:s {
 if [count 6 in ROLL] { result: 6 } \ 6 \
 if [count {5,6} in ROLL] { result: 5 } \ 5+ \
 if [count {4,5,6} in ROLL] { result: 4 } \ 4+ \
 result: 0
}

Alternatively, you can observe that rolling at least one of a number or higher is equal to just looking at the single highest die.

loop DICE over {1..10} {
 output [highest 1 of DICEd6] named "[DICE]d6"
}

The Transpose button

From here, you can use the "Transpose" button to swap the role of series and x-axis labels. This puts the pool size on the x-axis and gives you the probability that the highest number rolled is exactly 4, 5, or 6.

enter image description here

If "Transpose" could be used in conjunction with "At Least", this would become a stacked area plot showing the percentages stacked on each other, which looks like this:

enter image description here

Here the vertical extent of each area is the chance of rolling exactly that result, and the vertical position of each series is the chance of rolling at least that result.

\$\endgroup\$
5
\$\begingroup\$

In this case, basic probability is easier than Anydice.

I would offer a more theoretical approach, that in this case seems easier than writing Anydice code.

Consider the first case: one rolls Nd6 and one has success when there is at least a result larger than 4.

The probability of such event is equal to 1 minus the probability to get an outcome lower than 4 in each die: $$ P(\text{at least one 4}^+) = 1 - P(\text{all dice lower than 4}). $$

The probability of having an outcome less than 4 on a d6 is 3/6 = 1/2. The probability of having both outcomes less than 4 on two d6 is (1/2)(1/2)=(1/2)2. Hence, the probability of getting all N dice less than 4 is (1/2)N: we have therefore an easy formula to get what you seek $$ P(\text{at least one 4}^+ \text{on } N \text{ rolls}) = 1- \left(\frac12\right)^N. $$

For the other cases, one has

  • target 5+: the probability to get all rolls less than 5 is 2/3, then $$ P(\text{at least one 5}^+ \text{on } N \text{ rolls}) = 1- \left(\frac23\right)^N. $$
  • target 6: the probability to get all rolls less than 6 is 5/6, then $$ P(\text{at least one 6 on } N \text{ rolls}) = 1- \left(\frac56\right)^N. $$

These formulae can be used in any graphic tool (even in a Excel file): I used them in MatLab and produced what you are searching for.

Plot of probabilities

Generalization

This can be generalized for a die with d faces and a target t: $$ P(\text{at least one t}^+ \text{on } N \text{ rolls}) = 1- \left(\frac{t-1}{d}\right)^N. $$

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .