Created
September 19, 2018 16:05
-
-
Save utilForever/ca8eff1c0270a9530918931b6f6a83ae to your computer and use it in GitHub Desktop.
Simple Rand class to roll dice.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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