•
2 min read
dice_core

dice_core is a Rust library, published on crates.io, that parses standard dice notation (such as 2d6+5) and generates random results, with detailed output including each individual die roll and the total.

Features

  • Standard notation: supports AdX (quantity d sides) syntax.
  • Multiple dice terms: roll several dice types in one expression, such as 1d20+1d4, including subtracting dice (2d6-1d4).
  • Modifiers: positive and negative modifiers, such as +5 or -2.
  • Detailed results: returns the total, the individual die faces and the applied modifier.
  • Seeded RNG: deterministic rolling from a 32-byte seed, useful for testing and replay systems.
  • Safe parsing: handles whitespace and either d or D, and rejects excessive values (at most 1,000 dice).

Usage

use dice_core::roll;

fn main() {
    match roll("2d6+3") {
        Ok(result) => println!("Result: {}", result), // "[3, 5] + 3 = 11"
        Err(e) => eprintln!("Error: {}", e),
    }
}

Built with

Rust, nom for parsing, rand and rand_chacha for random number generation, and thiserror for error handling.