I was working on a project and found myself needing the ability to roll dice. After writing a small library for just that purpose, I thought I’d share it in case anyone else may have similar needs.
A few notes:
– This is my very first time sharing any kind of code, so feedback is very welcome.
– The library currently only deals with numerical dice.
– The library currently only works with dice for which each number is equally probable (i.e., no duplicate faces).
– The library does not use a cryptographically secure number generator, as the goal is to approximate randomness while still maintaining performance.
Other than that, it is pretty straightforward. It allows the user to create a Die object with a given lower bound and upper bound, add an optional list of modifiers that are applied to each roll, and roll as many times as needed. It also supports both synchronous and suspendable versions of the rolling functions.
In any case, I hope this is useful to someone. I do plan to add a few features (i.e., dice with duplicate faces, non-numerical dice), but I also intend to keep the library small.