Skip to content

Instantly share code, notes, and snippets.

@Kittoes0124
Created June 11, 2019 18:26
Show Gist options
  • Save Kittoes0124/f71838f6e63aa75071ea462c195cfff9 to your computer and use it in GitHub Desktop.
Save Kittoes0124/f71838f6e63aa75071ea462c195cfff9 to your computer and use it in GitHub Desktop.
public sealed class Die
{
private readonly int m_numberOfSides;
private readonly IRandomNumberGenerator m_rng;
public Die(int numberOfSides, IRandomNumberGenerator rng) {
if (0 > numberOfSides) {
throw new ArgumentOutOfRangeException(actualValue: numberOfSides, message: "value must be greater than zero", paramName: nameof(numberOfSides));
}
m_numberOfSides = --numberOfSides;
m_rng = rng;
}
public int Next() => m_rng.NextInt32(0, m_numberOfSides);
}
public sealed class Dice
{
private readonly Die[] m_dice;
public Dice(params Die[] dice) {
m_dice = dice;
}
public long Throw() {
var result = 0L;
foreach (var die in m_dice) {
result += die.Next();
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment