Skip to main content

Crate roll

Crate roll 

Source
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§

DiceExpr
A parsed dice expression such as adv 2d10+1d4+3.
DiceGroup
A group of identical dice, e.g. 2d10 means 2 ten-sided dice.
RollStats
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).
ParseError
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 target using Monte Carlo simulation.
exact_probability
Compute the exact probability of rolling at least target via 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.