NAME 

roll - rolls a user-defined dice sequence

SYNOPSIS 

roll [-vh] [--version] expression

DESCRIPTION 

roll Rolls a user-defined dice sequence. The dices to roll are defined using dN where N is the number of sides. Dices can be rolled multiple times by prepending the number of repetitions (e.g., 3d6) and used in simple mathematical expressions (e.g., 2d8+4).

OPTIONS 

-h
help
-v
verbose (displays the result for each roll)
--version
prints the version of the program

EXPRESSIONS 

Expressions are in dice notation (also known as dice algebra, common dice notation or RPG dice notation)

Die rolls are expressed in the form NdX or NDX where N is the number of dices (1 if omitted) and X the number of dice faces.

If the final number is omitted, it is assumed to be a six.

To this basic notation, an additive modifier can be appended, yielding expressions of the form, NdX+C. The plus can be replaced by a minus sign ("-") for subtraction. C is a number to be subtracted from the final total.

See: http://en.wikipedia.org/wiki/Dice_notation

Percentile dice (d%) 

Often, the variable X in the above notation will be "%". Although a 100-sided die does exist, it is both more common and more uniformly random to use a combination of two ten-sided dice known as percentile dice, where one die represents tens and the other units. A roll of two zeroes means 100.

If you want to roll a single 100-sided die use the "d100" notation.

Multipliers 

In some games, the above notation is expanded to allow for a multiplier, as in NdXxC or CxNdX, where "x" or "*" denotes multiplication (can be replaced by "/" for division) and C is a natural number.

Results are rounded up.

Selective results 

It is possible to keep only the M highest or lowest dices with the following notation:

NdXhM: roll N dices with X sides and keep the highest M results (M must be less or equal N)
NdXlM: roll N dices with X sides and keep the lowest M results (M must be less or equal N)

Examples 

3d6 rolls 3 6-sided dices and sums the results (can be abbreviated with "3d")
1d8 + 3 rolls 1 8-sided die and adds 3 (can be abbreviated by "d8+3")
d% rolls 2 10-sided dices: one represents tens and the othe units
1d6x5 rolls 1 6-sided dice and multiplies the result by 5
1d6 / 2 rolls 1 6-sided dice and divides the result by 2 (1d3)
4d6h3 rolls 4 6-sided dices and keeps the 3 highest results (discarding the lowest)

Grammar (EBNF) 

expression := term [ "+" term | "-" term ] .
term := number | factor [ ("*"|"/") number | number ("*"|"/") factor | "(" expression ")" .
factor := number dice [ ("h"|"H"|"l"|"L") number ] | dice .
dice := "d" | "D" [ number | "%" ] .

SEE ALSO 

(3)

EXIT STATUS 

roll returns a zero exist status if it finds no error in the supplied expresssion

BUGS 

Please report bugs to: Matteo Corti (matteo.corti (at) id.ethz.ch)

AUTHOR 

Matteo Corti (matteo.corti (at) gmail.com)