# Calculating dice pool probability with limited rerolls

I need a probability calculation script that works with various dice and dice pool sizes, that accounts for a mechanic that allows you to reroll up to X dice that are failures, but ONLY once per die. For example, if your dice pool is 5d10, and you roll four successes, you only get one reroll no matter how many rerolls you actually have. Essentially, I am trying to determine if a "limited" rerolls mechanic could be considered equivalent in usefulness compared to directly increasing your dice pool, or if there is a significant difference in the power level of these two mechanics.

This should be fairly simple for the right person, but I am no good at probability nor at using Troll or Anydice, so here I am. Thanks in advance.

• @KyleWilley Read the question statement again: the user isn't saying "You're not allowed to use an existing tool or do the math," they're saying "I don't know how to do this using existing tools or pure math, so I am asking you to show me." Feb 24, 2014 at 4:50
• Varna, it's actually pretty tricky with AnyDice, though we have figured out how to do it. Check out this question for a possible starting point. Is this the kind of thing you're looking for, just for d10 dice pools? Is the target number (N for which d10 >= N is a success) fixed or variable? Feb 24, 2014 at 4:54
• @Tridus, it's not off-topic, it's talking about probability and stuff that falls within tabletop game design canon. It's addressing not knowing how to do something, but it's still on topic, as it's useful to other tabletop game designers. Feb 24, 2014 at 5:02
• @AlexP, I don't actually know that AnyDice supports this function any more easily than it would be for me to teach Varna to write the PHP from scratch, which essentially just runs through 10,000 tests as if they were normal to simulate the effects of an actual probability calculator. Feb 24, 2014 at 5:02
• @KyleWilley That is off topic. Probability this complicated belongs on Mathematics.SE. Writing a script to do this belongs on one of the code stacks, depending on exactly how and what gets asked. This is not RPG & Advanced Probability Script Writing SE. Feb 24, 2014 at 5:06

## Rerolls are almost always identical to just adding dice.

The only time that rerolls would not be taken as just being additional dice is, to my knowledge, in only two cases: when enough dice succeed to prevent all the rerolls from being used, or when there are too few original dice to make the rerolls practical. If you can reroll failures again, this becomes less significant, but even then you're still doing not much more than doing the addition process again.

I even wrote a script to test this, if you feel like giving it a whirl. In some rare cases it might be possible to game the mechanics to do something other than just adding dice (I'm an English Education major, so take that with a grain of salt), but at that point you'd be designing a mechanic around creating interesting probabilities rather than making a game that rewards rerolls.

You could experiment with using modifier on rerolls or original results, which would produce results distinct from just adding a die, or using different dice, but I don't think that's what you intended.

Rerolls become less meaningful when the target number is low and when the reroll pool is large relative to the total of dice, and are more meaningful when you have a high target number and/or lots of dice. Each subsequent reroll opportunity is exponentially less valuable than the one before it.

• Note that you can leave values on the script to 0. If you want to see what I mean when I say that there's no meaningful difference between rolling 10 dice with one reroll and rolling 11 dice with none, just put the appropriate values in. Feb 24, 2014 at 5:28
• Wow, that was fast. This answered my question entirely. It does seem that adding dice and rerolling dice in this manner are about on par statistically, and the relationship between the dice pool size limiting the maximum rerolls will work nicely for making sure whichever stat gives rerolls isn't simply increasing a player's total potential for every pool. Thank you very much, I appreciate the effort. Feb 24, 2014 at 5:47
• You may want to add something about the conditions you tested before concluding that it's "almost always identical". My first test run was 10 dice, no rerolls (avg. 6.0057 successes) vs. 5 dice, 5 rerolls (avg. 4.2061 successes), using d10s and a target of 5 both times. 6.0 successes vs. 4.2 is fairly significant... Feb 24, 2014 at 12:09
• @DaveSherohman You are correct. I wrote this right before going to bed and I forgot that important caveat. If you have too few dice to take advantage of all the rerolls you will have fewer successes. However, I doubt you'd see a lot of practical play conditions where you'd have that many rerolls; they're not preferable to having more dice (ever!), and unless the success threshold is high there's a decent enough chance of just succeeding on the first time. Feb 24, 2014 at 14:53
• @DaveSherohman I originally tested d10s and did some various runs with TN of 7, but I was also testing low amounts of d4s (5 with no rr vs 3 with 2 rr), with a TN of 2 and a TN of 4. For this, in the case of lower TNs, more dice does become preferable by a decent marigin, but the way the mechanics work for what I am designing makes this acceptable to me. Thanks for pointing that out, though. Feb 24, 2014 at 19:46

I can't give you exact probabilities, but I can say that an extra die is strictly superior to a reroll. ("Strictly superior" meaning that it's sometimes better and never worse.)

Given this particular set of options, an extra die is nearly always superior. Both are equivalent only when there is no chance of success. In all other cases, an extra die is superior.

Why is this the case? "One die with a reroll" is equivalent to "roll two dice, but only count one success, even if both succeed".

For a concrete example, if there's an 80% chance to succeed and 20% to fail (equivalent to a d10 with target 3+):

• One die with reroll has a 4% (0.20 x 0.20) chance to completely fail, leaving a 96% chance of one success. That's an average of 0.96 successes.

• Two dice have the same 4% chance to completely fail, but they also have a 64% chance (0.80 x 0.80) of getting two successes, leaving a 32% chance of one success. Being able to get two successes raises the average total to 1.6 successes.

As the chance of each individual die succeeding shrinks, the two methods come closer to parity - at 10% succeed/90% fail you average 0.19 successes for one with reroll and 0.21 successes with two dice - but two dice will always remain better until you reach 0% chance per die and you're guaranteed to get no successes either way.

I suspect that it depends on how you count failures.

Is "5 dice, 4 successes, 1 failure" better/worse/equal than/to "6 dice, 4 successes, 2 failures"? If both the number of successes and failures count, it is a tricky question to answer (easy-ish to simulate, though). If the number of failures do not count, I would agree with Dave Sherohman that extra dice are always "never worse" in a strict succeed/fail system (no criticals either way).

## Solution on AnyDice

Link.

function: INITIAL:s reroll up to MAX_REROLL:n using DIE:d {
BAD: -[maximum of -DIE]
NUM_REROLL: [lowest of [count BAD in INITIAL] and MAX_REROLL]
result: INITIAL - NUM_REROLL * BAD + NUM_REROLL d DIE
}

function: N:n pool DIE:d reroll up to MAX_REROLL:n {
result: [N d DIE reroll up to MAX_REROLL using DIE]
}

output [5 pool (d10>=6) reroll up to 1]


In fact, this can reroll any dice that rolled the lowest outcome on any type of dice, not just success-counting dice.