# Why is Anydice giving me a larger result than expected?

In the wonderful anydice program I created a simulation of the rolls and damage of my level 1 Rogue character in 5e DnD against an enemy of AC of 16. My maximum damage should be 25 (6 from sneak attack, 8 from rapier, 6 from shortsword, 5 from dex). It may appear as though I am adding an extra 1d6 but that is the sneak attack that should only activate when I missed my first attack. I have been trying to work this out for the last hour with test cases and all but I can't figure out why the damage is going above 25. I have coded before so I know that sometimes the best solution is fresh eyes.

Here is the anydice code:

\Probability of Damage\
AC: 16
FH: ((1d20 + 7) >= AC)
SH: (1d20 >= AC)
SA: \1d2 - 1\ 1
output  ((FH*(1d6*SA + 1d8 + 5)) + (SH*(1d6 + (FH=0)*1d6*SA)))


• Check out our formatting help on preformatted text for how to insert code blocks into your posts. I've edited your post to use that formatting. Commented Apr 7, 2017 at 0:35
• You can't use a rapier with a shortsword without the Dual Wielder feat. If you have it, you can use two rapiers. Commented Apr 7, 2017 at 7:45
• Yeah my DM let me. It's probably because we have a really weak front line. But if I want 2 rapiers I still have to get the feat. Commented Apr 7, 2017 at 15:33

This is hard to explain, because it has to do with how Anydice works on a fundamental level. It's easy to show how it doesn't work, though. Replace your output with this:

output FH + FH


The fact that 1 is a possible result here is why your code isn't working the way you want it to. As I said, it's hard to explain why that is. Rather than try to write an explanation myself, possibly giving you all kinds of incorrect notions, I'll pass the buck to this answer on another question, which includes a pretty good explanation of this phenomenon.

It's a lot easier to fix than it is to explain, though!

AC: 16
DEX: 5
PROF: 2
SA: 1d6

function: first A:n second B:n {
if A + DEX + PROF >= AC & B + DEX + PROF >= AC {result: 1d8 + 1d6 + DEX + SA}
if A + DEX + PROF >= AC {result: 1d8 + DEX + SA}
if B + DEX + PROF >= AC {result: 1d6 + SA}
result: 0
}

output [first d20 second d20]