RollerConfig.RollDie Property

From DiceRoller Documentation

Gets or sets the function used to generate results when a die is rolled.

  • Namespace: Dice
  • Assembly: DiceRoller (in DiceRoller.dll)

Syntax

public Func<int, int, int> RollDie { get; set; }

Property Value

Type: System.Func<System.Int32, System.Int32, System.Int32>

The callback delegate that is used to populate die rolls.

Remarks

The delegate should take in the minimum and maximum amount to be rolled (both inclusive) and return an integer within that range.

If null, the default implementation will call GetRandomBytes repeatedly until a non-biased answer is given, and use that as the result.

Examples

The following example causes all dice to roll their maximum result.

using System;
using Dice;

class Sample
{
    public static void Main()
    {
        Roller.DefaultConfig.RollDie = RollDie;
        var result = Roller.Roll("2d20");
        Console.WriteLine(result.Value); // writes 40
    }

    public static int RollDie(int min, int max)
    {
        return max;
    }
}