< Dice | RollerConfig
Difference between revisions of "Dice/RollerConfig/RollDie"
From DiceRoller Documentation
(Created page with "{{APIdoc|RollerConfig.RollDie Property}} Gets or sets the function used to generate results when a die is rolled. {{ns}} == Syntax == <syntaxhighlight lang="C#"> public Func...") |
m (→Examples) |
||
Line 20: | Line 20: | ||
== Examples == | == Examples == | ||
− | The following example causes all dice to their maximum result. | + | The following example causes all dice to roll their maximum result. |
<syntaxhighlight lang="C#"> | <syntaxhighlight lang="C#"> |
Latest revision as of 17:50, 23 December 2018
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;
}
}