Skip to content

natri0/dice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

a dice roller library

a dice roller library for Rust, supporting most common modifiers.

features

  • standard notation (e.g. 3d6, etc.)
  • modifiers (e.g. 3d6kh2, 4d10r1, etc.)
  • explosions! (e.g. 1d6!6, 2d10x10, etc.)
  • command-line tool to roll dice from terminal

not supported (yet?)

  • fate/fudge dice
  • math

usage example

simple

use dice::roll;

fn main() {
    let values = roll("3d6");
    println!("3d6: {:?} (sum: {})", values, values.iter().sum::<i32>());
}

or, with the command line tool,

$ roll 4d6kh3
[4, 4, 1] (3) = 9

min/max values

use dice::Roll;

fn main() {
    let roll: Roll = "4d6rr1kh3".try_into().unwrap();
    let min = roll.min();
    let max = roll.max();

    println!("min: {:?}, max: {:?}", min, max);
}
$ roll --stats 4d6rr1kh3
min: 6, max: 18

cli json output

$ roll -j 2d10
{
  "rolls": [
    {
      "events": [],
      "rolls": [
        3,
        9
      ],
      "original_rolls": [
        3,
        9
      ],
      "sum": 12
    }
  ]
}
$ roll -j 1d6x6
{
  "rolls": [
    {
      "events": [
        {
          "Explode": {
            "index": 0,
            "new_value": 4
          }
        }
      ],
      "rolls": [
        6,
        4
      ],
      "original_rolls": [
        6
      ],
      "sum": 10
    }
  ]
}

license

MIT licensed, see license for details.

About

a dice roller library & cli tool

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages