Created
June 11, 2019 18:26
-
-
Save Kittoes0124/f71838f6e63aa75071ea462c195cfff9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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