Expand description
A dice roller library for tabletop RPGs.
Supports standard dice notation (e.g. 2d10+4), advantage/disadvantage,
keep-highest/lowest (4d6kh3), and Monte Carlo / exact probability estimation.
§Examples
use roll::{parse_expr, Modifier};
let expr = parse_expr("2d10+4").unwrap();
assert_eq!(expr.flat_bonus, 4);
assert_eq!(expr.modifier, Modifier::None);
assert_eq!(expr.groups.len(), 1);
assert_eq!(expr.groups[0].count, 2);
assert_eq!(expr.groups[0].sides, 10);Structs§
- Dice
Expr - A parsed dice expression such as
adv 2d10+1d4+3. - Dice
Group - A group of identical dice, e.g.
2d10means 2 ten-sided dice. - Roll
Stats - Theoretical statistics for a dice expression (min, max, mean).
Enums§
- Keep
- Keep rule applied to a dice group after rolling.
- Modifier
- Modifier applied to a dice roll (advantage, disadvantage, or none).
- Parse
Error - Error type for dice expression parsing failures.
Functions§
- compute_
distribution - Run a Monte Carlo simulation and return the count of each result value.
- estimate_
probability - Estimate the probability of rolling at least
targetusing Monte Carlo simulation. - exact_
probability - Compute the exact probability of rolling at least
targetvia polynomial convolution. - format_
rolls - Format roll results as a human-readable string like
[3, 5] + [2]. - parse_
expr - Parse a dice expression string into a
DiceExpr. - render_
distribution - Render a probability distribution histogram as a string.
- roll_
once - Roll the dice once, returning the total and the kept dice per group.
- roll_
stats - Compute theoretical min, max, and mean for a
DiceExpr. - roll_
value - Roll and return just the final value, applying advantage/disadvantage.
- roll_
verbose - Roll with detailed output, returning the total and a human-readable breakdown.