Crates.io | dice_forge |

lib.rs | dice_forge |

version | 0.3.0 |

source | src |

created_at | 2023-03-08 18:17:04.581769 |

updated_at | 2024-01-08 14:24:08.227606 |

description | A small crate to preform basic math using dice notation for random numbers |

homepage | |

repository | https://github.com/domiryuu/DiceForge |

max_upload_size | |

id | 804841 |

size | 56,611 |

DiceForge is a Rust library for simulating dice rolls. It provides a simple and easy-to-use API for generating random dice rolls and calculating probabilities of different outcomes.

Supports standard dice notation (e.g. 1d6, 2d10, etc.) Add, subtract, or even multiply modifiers to rolls

To use DiceForge in your Rust project, add the following to your Cargo.toml file:

```
[dependencies]
dice_forge = "0.2.2"
```

To roll a standard six-sided die, you can use the roll function on a compiled `Equation`

object:

```
use dice_forge::Equation;
let die = Equation::new("1d6").unwrap();
let roll = die.roll().unwrap();
println!("You Rolled a {}", roll);
```

You can also add modifiers to your rolls:

```
use dice_forge::Equation;
let die = Equation::new("1d6+5").unwrap();
let roll = die.roll().unwrap();
println!("You Rolled a {} with a +5 modifier", roll);
```

It even takes order of operations into consideration so you could write an equation as complicated as

```
use dice_forge::Equation;
let die = Equation::new("3+1d6(4+3^2)-6/2").unwrap();
let roll = die.roll().unwrap();
println!("You Rolled a {}", roll);
```

If you do not want to create an `Equation`

object you can directly roll the equation:

```
use dice_forge::roll;
let damage = roll::roll("1d6").unwrap();
println!("You do {} damage", damage);
```

You can also roll with advantage or disadvantage:

```
use dice_forge::Equation;
let die = Equation::new("d20").unwrap();
let mut roll = die.advantage().unwrap();
println!("You rolled {} with advantage", roll);
roll = die.disadvantage().unwrap();
println!("You rolled {} with disadvantage", roll);
```

You can check out the rest of the documentation at docs.rs

Contributions are welcome! If you find a bug or want to add a new feature, please submit a pull request on GitHub.

or if you would like you can support me: