fork download
  1. using System;
  2.  
  3. public class Die
  4. {
  5. private static Random _random = new Random();
  6.  
  7. public int CurrentRoll { get; private set; }
  8.  
  9. public int Min { get; private set; }
  10.  
  11. public int Max { get; private set; }
  12.  
  13. public Die(int min, int max)
  14. {
  15. Min = min;
  16. Max = max;
  17. Roll();
  18. }
  19.  
  20. public int Roll()
  21. {
  22. CurrentRoll = _random.Next(Min, Max+1); // note the upperbound is exlusive hence +1
  23. return CurrentRoll;
  24. }
  25. }
  26.  
  27. public class Test
  28. {
  29. public static void Main()
  30. {
  31. Die d1 = new Die(1, 6);
  32. Die d2 = new Die(1, 6);
  33.  
  34. Console.WriteLine("d1: " + d1.Roll());
  35. Console.WriteLine("d2: " + d2.Roll());
  36. Console.WriteLine("d1: " + d1.Roll());
  37. Console.WriteLine("d2: " + d2.Roll());
  38. Console.WriteLine("d1: " + d1.Roll());
  39. Console.WriteLine("d2: " + d2.Roll());
  40. Console.WriteLine("d1: " + d1.Roll());
  41. Console.WriteLine("d2: " + d2.Roll());
  42. }
  43. }
Success #stdin #stdout 0.03s 34712KB
stdin
Standard input is empty
stdout
d1: 4
d2: 6
d1: 2
d2: 4
d1: 1
d2: 5
d1: 4
d2: 3