Skip to content

Instantly share code, notes, and snippets.

@utilForever
Created September 19, 2018 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save utilForever/ca8eff1c0270a9530918931b6f6a83ae to your computer and use it in GitHub Desktop.
Save utilForever/ca8eff1c0270a9530918931b6f6a83ae to your computer and use it in GitHub Desktop.
Simple Rand class to roll dice.
#include <random>
#include <iostream>
class Rand
{
public:
Rand()
{
m_generator.seed(m_device());
decltype(m_distribution.param()) range(1, 6);
m_distribution.param(range);
}
void RollDice()
{
for (size_t i = 0; i < 10; ++i)
{
std::cout << m_distribution(m_generator) << ' ';
}
std::cout << std::endl;
}
private:
std::random_device m_device;
std::mt19937 m_generator;
std::uniform_int_distribution<int> m_distribution;
};
int main()
{
Rand r;
r.RollDice();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment