   C++ Handling Dice Rolls
  I've been tinkering around with my DnD battle sim again, and while checking out source from other similar projects, I began wondering if I had been handling my dice code wrong.  it generates the numbers I need just fine, it's how the Roll function is accessed that I'm wondering about.I've seen(1) the intro-to-programming way...a function at global scope with its prototype included where a class requires a dice roll:int Roll(int Quantity, int Size);(2) a static method of a Dice class, called without creating a Dice object (header file included where necessary):class Dice{   public: static int Roll(int Quantity, int Size);};called with Dice::Roll(int, int) where a dice roll is needed(3) dice objects of a particular dice size, with a roll being generated by calling the Roll method:class Dice{   private: int Size;   public: Dice(int) : Size(int); int Roll(); int Roll(int Quantity);}Dice * d20 = new Dice(20);d20->Roll();I can understand #3 in the case that I want to use a particular dice object in a way other than just to generate a roll -- for example, if I want to have an animation of it being rolled or for some reason need to use the same die somewhere else. If I'm only concerned about the value of any given roll, is there a good reason to create dice objects and call their Roll() method when I need a dice roll in my code?  Alternatively, should I create a set of dice objects that exist throughout the life of my program and pass them to all the parts of my code that need a dice roll?OR are #1 and/or #2 more appropriate if a random number in the necessary range is all I care about?Finally, are there reasons to use #2  vs. #1?Thanks.   
  The only reason to choose #2 over #1 would be encapsulation, but unless you actually need a Dice object for any reason I'd probably use a namespace rather than a class with a static member.namespace Dice {  int Roll(int Quantity, int Size);}// get a dice valueint roll = Dice::Roll( 1, 6 );I wouldn't worry about maybe needing an animated dice rolling at some point in the future. Whatever plan you come up with now will probably have changed by the time you reach that stage!   ;  Keep things simple and go with #1. It's really redundant to create the class with a static function.RollDice() would be a better name :) (as it's not in a class)   ;  Writing an own class is senseful if some state is to be stored with individual dice. Some examples:The number of sides is a less senseful example, because returning the diced number makes no sense if the number of sides is not known. But when the number of sides can be requested by e.g. Dice::numberSides() ... Let's assume that a client should work with a dice where the number of sides is prescribed by some rule outside the scope of the client. Then creating an instance of Dice with the number of sides specified in its c'tor (as the example in the OP shows) and passing that to the client is a possibility.Another, perhaps more noticeable example is when the probability of a dice should be adapted during gameplay. Assume that a player has to dice as long as a specific event occurs. That can durate long, so that the player gets more and more frustrated with every round. We can overcome this by increasing the probability of the desired event slightly with each unsuccessful trial (resetting to the nominal probability if the desired event occurs). This means that we have to track how many unsuccessful trials have gone; a typical application for a Dice class.   ;  I would use template for sides, and feed the constructor with the randomobject. This makes the dice class more testable.template<unsigned SIDES, typename RANDOM_POLICY>class Dice {public:    enum { Sides = SIDES };    explicit Dice(const RANDOM_POLICY & random) : m_random(random) { }    int Roll(int Quantity) {   return (Quantity>0)?(m_random.getInt()%SIDES)+Roll(Quantity-1)+1:0;    }private:    RANDOM_POLICY m_random;};Possibly using a default random object when constructing the dice.   