I want to know how to keep a mersenne random number generator as a member variable and use it in the same class.
I wrote the class as below and it works perfectly, but I do not like the that std::mt19937
is initialized. I would like to know whether there is a way to initialize it in the constructor of Test
?
#include <iostream>
#include <cmath>
#include <random>
#include <chrono>
#include <ctime>
class Test{
public:
Test()
{
}
void foo()
{
auto randomNum = std::uniform_int_distribution<>(0, threads.size())(rnd);
}
private:
std::mt19937 rnd
{
std::chrono::high_resolution_clock::now().time_since_epoch().count()
};
}