Question: I don't intend on implementing this into an application yet as I'm going to test it first. As such, it doesn't do much beyond rolling. It also overloads some "typical" operators such as `==` and `!=`.

Most of all, I'm still very unsure about my random number generator. I've read about `<random>`'s `std::uniform_int_distribution` and that it has advantages over `std::rand`, but I'm also not sure if I've put it in a good place. Client code will be forced to use my seed *if* my source file is used, but my header file is free from this.

What could be said about my RNG use? Anything else that could be done?

**Dice.h**

```
#ifndef DICE_H
#define DICE_H

#include <ostream>

class Dice
{
private:
    int topValue; // same default type as std::uniform_int_distribution<>

public:
    void roll();
    int value() const { return topValue; }
};

// the C++ FAQ on SO suggests that these overloads are best as non-members

inline bool operator==(Dice const& lhs, Dice const& rhs) { return lhs.value() == rhs.value(); }
inline bool operator!=(Dice const& lhs, Dice const& rhs) { return !operator==(lhs, rhs); }
inline std::ostream& operator<<(std::ostream& out, Dice const& obj) { return out << obj.value(); }

#endif

```

**Dice.cpp**

```
#include "Dice.h"
#include <random>

std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dis(1, 6);

void Dice::roll()
{
    topValue = dis(gen);
}

```

Answer: 
Some points to add to the others:

* It seems arbitrary to force clients to make two calls for every roll. `roll` should return the value. You can keep the method to read it, but don't force it's use.
* While I understand the meaning of `topValue`, I would prefer `lastRoll`.
* Add `numSides` to the constructor to allow d20 et al. This value and the type of distribution--uniform, normal, fixed (for testing), etc.--should determine equality. Two dice are equal if they produce similar sequences--not when they happened to roll the same number previously.
* What happens if I access the last roll before rolling the die for the first time? Does this make sense?
Another victim of STL (the guy)'s "rand() Considered Harmful" presentation. I too went and verified that my code was using the random number generators correctly.

Aside from @AntonGolov's advice, I would also mention that Dice::roll is not thread safe. If you have multiple threads rolling dice, then they may cause some weird behaviour.