using System; // // Class for simulating a die // (object "rolled" to generate a random number) // class Dice { private int myRollCount; // # times die rolled private int mySides; // # sides on die // random number generator private Random myRandomNumbers; // constructor, sides specifies number of "sides" // for the die, e.g., 2 is a coin, 6 is a 'regular' die public Dice(int sides) { myRollCount = 0; mySides = sides; myRandomNumbers = new Random(); } // // returns the random "roll" of the die, a uniformly // distributed random number between 1 and # sides // public int Roll() { // update # of times die rolled myRollCount += 1; // generate random number in range [1..mySides] return myRandomNumbers.Next(1, mySides + 1); } // // returns # of sides // public int NumSides() { return mySides; } // returns # of times Roll called // for an instance of the class public int NumRolls() { return myRollCount; } }