# How can I calculate the distribution of 3d6, keep and rerolling any 1s and 2s, once? [duplicate]

The way my DM wants to try is roll 3d6 and reroll any 1's or 2's once. If you roll a 2 and the reroll ends up being a 1 you have to take the 1.

• If you rolled a 2, and rerolled it as a 1, are you supposed to reroll it again since only one has been rerolled once? Is the reroll tied to the number or the die? – Fering Aug 18 '20 at 21:07
• I assumed (perhaps incorrectly) it was a situation like great weapon fighting "You may reroll once, but must use the new roll" So rerolling 2's is technically a risk, but statistically a good choice. – Daveman Aug 18 '20 at 21:23

You can do it like this, using the helper function from this answer:

function: ROLL:n replace FILTER:s with REROLL:d {
if ROLL = FILTER { result: REROLL }
result: ROLL
}

X: [d6 replace {1,2} with d6]
output 3dX named "3d6, reroll 1 and 2 once"


Note that I'm first defining a custom die X that represents a single d6 with 1s and 2s rerolled once, and then rolling three of these custom dice. Especially with large pools of dice this is significantly more efficient than rolling the whole pool at once and feeding the results into a custom function as sequences, since in that case AnyDice isn't smart enough to realize that the individual dice in the pool cannot affect each other.

https://anydice.com/program/1d573

This should do what you are wanting with a single d6, its a modified great weapon fighting script. I have updated the program to follow common practices better.

function: reroll R:n under N:n {
if R < N { result: d6 } else {result: R}
}
output 3d[reroll 1d6 under 3]

• Oh, and because I'm an idiot and forgot to include it in the first comment: you should also explain how the code works, so a reader can see why this is correct and how to solve this kind of problem (something about teaching a fish) – Someone_Evil Aug 18 '20 at 22:12

## You just need a 36 sided dice

output 3d{1:2,2:2,{3..6}:8}

• You should really explain how this works, because while it's probably correct, it's not an intuitive solution so showing why it's correct and how to do are important parts of a good answer. – Someone_Evil Aug 18 '20 at 22:14
• An 18-sided die suffices... – rasher Sep 16 '20 at 21:04