Dungeons and Dragons Tool

Back to main page

The Scenario

You are a Dungeon Master for a D&D campaign.
You want your player to roll a die to determine the outcome of some scenario, and you want to choose precisely the expected value of the player's roll.
However, you have your principles: you don't want to go beyond the rules of D&D (except for the rule that says advantage and disadvantage don't stack).
Thankfully, using some sequence of advantage and disadvantage, you can create a distribution with any expected value you choose (provided that it's between 1 and the number of sides on the die being rolled).
The tool on this page does most of the hard work for you.

The Tool

When reading the output of this tool, note that "with" is left associative.
For example, "roll a d20 with advantage with disadvantage with advantage" means that you'll take advantage on "roll a d20 with advantage with disadvantage," et cetera.
This means that if there are n tokens ("advantage" or "disadvantage") in the output, you'll have to roll 2n dice in total.

Number of sides on the die:

Desired expected value:

Acceptable margin of error:

Source Code

To use the following source code you'll need to have ghc installed.
To compile the program, type "ghc -O Main.hs".
To run it type "./Main n e a" where n, e, and a are the values you would type in the above input boxes.