DiceTray 1.1.1

dotnet add package DiceTray --version 1.1.1
                    
NuGet\Install-Package DiceTray -Version 1.1.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DiceTray" Version="1.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DiceTray" Version="1.1.1" />
                    
Directory.Packages.props
<PackageReference Include="DiceTray" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DiceTray --version 1.1.1
                    
#r "nuget: DiceTray, 1.1.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DiceTray@1.1.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DiceTray&version=1.1.1
                    
Install as a Cake Addin
#tool nuget:?package=DiceTray&version=1.1.1
                    
Install as a Cake Tool

DiceTray

A cryptographically random dice rolling library for tabletop RPG applications, built on System.Security.Cryptography.RandomNumberGenerator for better randomness than the standard System.Random library.

Available on NuGet.org and jamescordrey.com.


Installation

dotnet add package DiceTray

Usage

DiceTray supports both a fluent interface and a non-fluent interface. Both styles are fully chainable and always return a RollResult object.

Fluent Interface

Roll a single d20:

using DiceTray;

RollResult result = Dice.Take(1).D(20).Roll();

Chain multiple dice groups:

RollResult result = Dice.Take(1).D(20).And(3).D(6).And(1).D(8).Roll();

Non-Fluent Interface

Roll 3d6:

RollResult result = Dice.Take(3, 6).Roll();

Chain multiple dice groups:

RollResult result = Dice.Take(1, 20).And(3, 6).Roll();

Mixing Styles

The two styles can be mixed freely in the same chain:

RollResult result = Dice.Take(1, 20).And(3).D(6).Roll();

Dice Notation

You can also pass a dice notation string directly to Roll():

RollResult result = Dice.Roll("1d20+2d10+3d6+2d8");

The notation is case insensitive and supports whitespace around the + separator:

RollResult result = Dice.Roll("1D20 + 2D10");

Invalid notation will throw an ArgumentException.


Results

Every call returns a RollResult object regardless of how many groups were rolled.

RollResult result = Dice.Take(1).D(20).And(3).D(6).Roll();

result.Total;                              // Grand total of all groups
result.Rolls.Count;                        // Number of groups (2 in this case)

result.Rolls[0].Sides;                     // 20
result.Rolls[0].Total;                     // Total of the 1d20
result.Rolls[0].IndividualRolls;           // int[] of each die result

result.Rolls[1].Sides;                     // 6
result.Rolls[1].Total;                     // Total of the 3d6
result.Rolls[1].IndividualRolls;           // int[] of each die result

RollResult

Property Type Description
Total int Sum of all roll group totals
Rolls List<Roll> Individual roll groups

Roll

Property Type Description
Total int Sum of all individual rolls in this group
Sides int Number of sides on the die
IndividualRolls int[] Each individual die result

License

MIT © Damadar


Changelog

1.1.1

  • Added XML documentation comments for IntelliSense support
  • Updated package icon

1.1.0

  • Added dice notation string parsing via Dice.Roll(string)
  • Supports case insensitive notation and whitespace

1.0.0

  • Initial release
  • Fluent and non-fluent interfaces
  • Cryptographically random number generation via RandomNumberGenerator
  • RollResult and Roll models with pre-calculated totals
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

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
1.1.1 338 2/27/2026

Initial release.