Show / Hide Table of Contents

Class Dice

The most important GoRogue.DiceNotation class -- contains functions to roll dice, and to retrieve an DiceExpression instance representing a given expression.

Inheritance
object
Dice
Inherited Members
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: GoRogue.DiceNotation
Assembly: GoRogue.dll
Syntax
public static class Dice

Fields

View Source

DiceParser

The parser that will be used to parse dice expressions given to the Parse(string) and Roll(string, IEnhancedRandom?) functions. If you want to use a custom parser, you can assign an instance to this field.

Declaration
public static IParser DiceParser
Field Value
Type Description
IParser

Methods

View Source

Parse(string)

Uses the IParser specified in the DiceParser variable to produce an DiceExpression instance representing the given dice expression.

Declaration
public static DiceExpression Parse(string expression)
Parameters
Type Name Description
string expression

The string dice expression to parse.

Returns
Type Description
DiceExpression

A DiceExpression instance representing the parsed string.

Remarks

Generally speaking, dice-parsing via the standard Roll(string, IEnhancedRandom?) method is extremely fast. However, if you are repeating a dice roll many times, in a case where maximum performance is absolutely necessary, there is some benefit to retrieving a DiceExpression instance instead of using the Roll function, and calling that expression's Roll(IEnhancedRandom?) method whenever a result is required.

View Source

Roll(string, IEnhancedRandom?)

Uses the IParser specified in the DiceParser variable to parse the given dice expression, roll it, and return the result. This is the standard method for rolling dice.

Declaration
public static int Roll(string expression, IEnhancedRandom? random = null)
Parameters
Type Name Description
string expression

The string dice expression to parse.

IEnhancedRandom random

RNG to use to perform the roll. If null is specified, the default RNG is used.

Returns
Type Description
int

The result of evaluating the dice expression given.

Remarks

This method is convenient and typically very fast, however technically, parsing is computationally more expensive than evaluation. If a dice expression will be rolled many times in a situation where maximum performance is required, it is more efficient to use the Parse(string) method once, and use the resulting DiceExpression instance to roll the expression each time it is needed.

  • View Source
In this article
Back to top Generated by DocFX