Normalizing Dice
odds for rerolls
When you use a custom function in AnyDice, it is possible to specify the empty die as a result. In fact, this happens implicitly if you do not define a result at all. What effectively happens is that the input values disappear from the die. Consequently, the odds no longer add up to 100%. At least, that is how it used to be.
I've changed AnyDice so that it normalizes the result, scaling the odds of all remaining values to account for those that were dropped.
Rerolling
This change allows us to easily represent a situation in which we would reroll the dice, discarding the previous result, until a certain condition is met. A classical example is an opposed roll without ties.
Consider a situation in which two sides both roll 2d6 and whichever side rolls higher wins, with a margin equal to the roll difference. In this case, there is an 11.27% chance that both sides roll equal and the result is a tie. If we do not want ties, we'll simple reroll the whole thing until it is no longer a tie.
You could respresent that in AnyDice by calling the function again, recursively. The downside of that is low performance and even failure, forcing you to reduce the maximum function depth, leading to imprecise odds. Now you can simply leave out those situations you don't want, and AnyDice accomodates easily.
function: A:n vs B:n reroll ties {
if A != B { result: A - B }
}
YOU: 2d6
THEM: 2d6
output YOU - THEM named "with ties"
output [YOU vs THEM reroll ties] named "without ties"
Alternatively, you could invert the conditional, making the empty die result explicit.
function: A:n vs B:n reroll ties {
if A = B { result: d{} }
result: A - B
}