Class AverageRollExtensions
Extension methods that compute the average roll of a die or collection of dice, rounded to a whole number.
public static class AverageRollExtensions
- Inheritance
-
AverageRollExtensions
- Inherited Members
Remarks
The average roll is the midpoint of the possible results, (MinValue + MaxValue) / 2, which is always
a whole number or a half. These methods round that midpoint to an int, which is convenient for
tabletop rules that call for average damage rounded a particular way — for example, half damage on a
successful save is conventionally rounded down.
Methods
AverageRoundedDown(IDice)
Returns the average roll of the dice, including the modifier, rounded down to the nearest whole number.
public static int AverageRoundedDown(this IDice dice)
Parameters
diceIDiceThe dice to average.
Returns
Examples
// 2d6 averages 7; half damage on a successful save, rounded down, is 3.
int half = new Dice(2, 6).AverageRoundedDown() / 2; // 3
Exceptions
- ArgumentNullException
diceis null.
AverageRoundedDown(IDie)
Returns the average roll of the die, rounded down to the nearest whole number.
public static int AverageRoundedDown(this IDie die)
Parameters
dieIDieThe die to average.
Returns
Examples
int average = new Die(6).AverageRoundedDown(); // 3.5 -> 3
Exceptions
- ArgumentNullException
dieis null.
AverageRoundedUp(IDice)
Returns the average roll of the dice, including the modifier, rounded up to the nearest whole number.
public static int AverageRoundedUp(this IDice dice)
Parameters
diceIDiceThe dice to average.
Returns
Examples
int average = new Dice(2, 6).AverageRoundedUp(); // 7.0 -> 7
Exceptions
- ArgumentNullException
diceis null.
AverageRoundedUp(IDie)
Returns the average roll of the die, rounded up to the nearest whole number.
public static int AverageRoundedUp(this IDie die)
Parameters
dieIDieThe die to average.
Returns
Examples
int average = new Die(6).AverageRoundedUp(); // 3.5 -> 4
Exceptions
- ArgumentNullException
dieis null.