The Basics
AnyDice can perform mathematical operations on numbers, like any regular calculator can.
- Addition
1 + 2yields3.- Subtraction
3 - 2yields1.- Multiplication
2 * 3yields6.- Integer division
- As AnyDice only supports whole numbers, all divisions are integer divisions, rounding toward zero. So
6 / 3yields2, while5 / 3yields1. - Exponentiation
2 ^ 3yields8.
-3). After that, it does
exponentiations, then multiplications and divisions, followed by additions and subtractions. It performs operations of the same precedence in the order
it encounters them, from left to right. You can use parentheses to change order in which the operations are performed.
Comments
Any text enclosed with a backslash character on either end –\ like this \ – will be ignored by AnyDice. This is useful
for writing explanations or for temporarily disabling some commands.
Variables
Variables are uppercase words, which may contain underscores. It is possible to assign something to a variable, so that you can reuse it later. Assigning something to a variable will replace its previous value.X: 3
output X named "It's a 3!"
output X + 1 named "It's a 4!"
X: X * 2
output X named "It's a 6!"
Conditions
AnyDice allows you to compare two values, to check whether a certain condition is true. If so, the result will be a1,
otherwise a 0. Condition operations have a lower precedence than all mathematical operations.
- Equal?
2 = 2yields1, while1 = 2yields0.- Not equal?
1 != 2yields1, while2 != 2yields0.- Smaller?
1 < 2yields1, while2 < 2and3 < 2both yield0.- Greater?
3 > 2yields1, while2 > 2and1 > 2both yield0.- At least?
2 >= 2and3 >= 2both yield1, while1 >= 2yields0.- At most?
1 <= 2and2 <= 2both yield1, while3 <= 2yields0.
Booleans
In general, the number0 represents no while any other number – either positive or negative – represents yes.
Using this logic, AnyDice allows you to perform boolean operations. This is useful if you like to check multiple conditions. Boolean operations
have a lower precedence than all conditions, except for Not, which is a unary operation.
In the examples below, assume that the variable YES is set to any number other than 0, while NO
is set to 0.
- And also
YES & YESyields1, while any other combination with aNOyields0.- Or else
NO | NOyields0, while any other combination with aYESyields1.- Not
!YESyields0, while!NOyields1.