d20tek-dicenotation
5.1.2
dotnet add package d20tek-dicenotation --version 5.1.2
NuGet\Install-Package d20tek-dicenotation -Version 5.1.2
<PackageReference Include="d20tek-dicenotation" Version="5.1.2" />
<PackageVersion Include="d20tek-dicenotation" Version="5.1.2" />
<PackageReference Include="d20tek-dicenotation" />
paket add d20tek-dicenotation --version 5.1.2
#r "nuget: d20tek-dicenotation, 5.1.2"
#:package d20tek-dicenotation@5.1.2
#addin nuget:?package=d20tek-dicenotation&version=5.1.2
#tool nuget:?package=d20tek-dicenotation&version=5.1.2
Introduction
d20Tek.DiceNotation
DiceNotation library written to provide dice notation parsing, evaluation, and rolling. This library is built on .NET 9, so you can incorporate it into any of your .NET Core and beyond projects.
Dice notation (also known as dice algebra, common dice notation, RPG dice notation, and several other titles) is a system to represent different combinations of dice in role-playing games using simple algebra-like notation such as 2d6+12.
The specification for the dice notation supported in the current version on the library is located here. There are also examples of dice notation strings.
To build the source code, please read Building Code page.
Installation
This library is a NuGet package so it is easy to add to your project. To install these packages into your solution, you can use the Package Manager. In PM, please use the following commands:
PM > Install-Package d20tek-dicenotation -Version 5.1.1
To install in the Visual Studio UI, go to the Tools menu > "Manage NuGet Packages". Then search for d20Tek.dicenotation and install it from there.
Read more about this release in our Release Notes.
Usage
d20Tek.DiceNotation has a couple of different modes that it can be used in depending on how you want to build up the dice expression:
Programmatically:
You can build up the dice to roll by coding the various parts that make up a dice expression. The expression can be build by chaining together operations (as a Fluent API style).
IDice dice = new Dice();
// equivalent of dice expression: 4d6k3 + d8 + 5
var expression = DiceExpression.Create().AddDice(6, 4, choose: 3)
.AddDice(8)
.AddConstant(5);
DiceResult result = dice.Roll(expression, new RandomDieRoller());
Console.WriteLine("Roll result = " + result.Value);
Dice Notation String:
You can also create the dice expression by parsing a string that follows the defined Dice Notation language. When you parse the text, we create a similar expression tree as the programmatic version that is then evaluated.
IDice dice = new Dice();
DiceResult result = dice.Roll("d20+4", new RandomDieRoller());
Console.WriteLine("Roll result = " + result.Value);
Dice Rollers:
Both of the usage options above use the RandomDieRoller, which uses the .NET Random class to produce the random dice rolls. There are additional die rollers:
- ConstantDieRoller - lets you create a roller that always returns the same value. This roller is great for testing features and expressions because the results will be consistent in your unit tests.
- CryptoDieRoller - uses Cryptography API to create a more random number generator.
- MathNetDieRoller - provides various strategies for random number generators to produce our die rolls.
Finally, the library defines a IDieRoller interface that you can use to build your own custom die rollers. If the random number generators in our libraries don't suffice, you can override it with your own rolling implementation.
Samples:
For more detailed examples on how to use this DiceNotation library, please review the following samples:
Feedback
If you use this library and have any feedback, bugs, or suggestions, please file them in the Bugs section of this repository.
I have plans for better notation support, so there will be updates coming for this project. Your feedback would be appreciated.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- MathNet.Numerics (>= 5.0.0)
-
net9.0
- MathNet.Numerics (>= 5.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 5.1.2 | 61 | 2/13/2026 |
| 5.1.1 | 102 | 1/14/2026 |
| 5.0.2 | 305 | 11/13/2025 |
| 4.0.7 | 333 | 9/18/2025 |
| 4.0.6 | 229 | 8/4/2025 |
| 4.0.5 | 199 | 7/4/2025 |
| 4.0.1 | 1,334 | 2/7/2024 |
| 4.0.0 | 231 | 1/25/2024 |
| 3.8.2 | 308 | 11/16/2023 |
| 3.4.2 | 381 | 4/7/2023 |
| 3.3.2 | 603 | 12/13/2021 |
| 3.2.3 | 693 | 11/24/2020 |
| 3.1.30 | 796 | 7/25/2020 |
| 3.1.24 | 689 | 7/9/2020 |
| 3.1.7 | 743 | 2/24/2020 |
| 3.0.3 | 820 | 2/6/2020 |
| 3.0.2 | 755 | 1/29/2020 |
Current release:
Upgrade library packages to .NET 10.
Release 1.0.5:
* Add dice notation for keep lowest by using L token in the notation. Changed drop lowest notation to use P token.
Release 1.0.4:
* Added tracking service to keep track of die rolls to provide statistical data.
* Added abstract RandomDieRollerBase class for shared code between all random rollers, so those classes can just implement minimally the number generation.
Release 1.0.3:
* Added value converters for DiceResult and TermResultList to help with default display of these classes as text.
* Two bug fixes:
- Added IDice.Clear method to allow dice to be reused with new expressions (without needing to recreating instance).
- Dice.Parse now throws an exception if null or empty string is used.
Release 1.0.2:
* Added support percentile (d%) notation.
* Added support for dropping lowest N dice (similar to keeping highest N dice).
* Added support for Fudge/FATE dice notation.
* Added support for exploding or pentrating dice rolls.
* Added support for default dice sides (3d =>3d6), and ability to set default number of sides as dice config.
Release 1.0.1:
* Added general purpose parser to handle more math and dice expressions.
* Added support for grouping using ( ). Now you can parse dice expressions like - (2+1)d4 - (4-2).
* Test validation for new expressions and grouping.