I want to know how to keep mersenne random number generatoras 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 whether there is a way to initialize it in the constructor of the Test class?
#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())(m_random);
}
private:
std::mt19937 m_random{std::chrono::high_resolution_clock::now().time_since_epoch().count()};
};
Aucun commentaire:
Enregistrer un commentaire