https://github.com/arranf/dice-roller
A library for computing the results of dnd dice input strings
https://github.com/arranf/dice-roller
Last synced: 9 months ago
JSON representation
A library for computing the results of dnd dice input strings
- Host: GitHub
- URL: https://github.com/arranf/dice-roller
- Owner: arranf
- License: mit
- Created: 2020-03-30T00:04:16.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-04-18T00:27:18.000Z (about 5 years ago)
- Last Synced: 2025-03-01T15:15:31.089Z (over 1 year ago)
- Language: Rust
- Size: 16.6 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dnd_dice_roller
A simple Rust library for taking a DnD like dice string as an input and calculating a result.
Supports advantage and disadvantage.
## Usage
```rust
use dice_roller::dice::{Dice, RollType};
use std::str::FromStr;
let dice = Dice::from_str("2d20 + 1")?;
// Roll dice uses thread RNG
let result = dice.roll_dice();
A single d20 with a plus five modifier and advantage
let second_dice = Dice::new(1, 20, Some(5), RollType::Advantage);
let results = second_dice.roll_dice();
```
## Example inputs
```
d6
2d6
2d6 + 3
d20 advantage
d20 adv
d20 a
2d20 + 4 advantage
2d20 - 2 adv
1d6 - 1 disadvantage
1d6 dadv
d6 d
```