What is wrong with my constructor? Every time I call a function that is supposed to generate random numbers, it generates the same numbers. Each call instantiates one of these objects below. I thought I was seeding m_gen
randomly with the output of m_rd
's operator()
call.
Could I pass in the result of m_rd()
to the constructor? What would the signature be? Shuffler(std::random device& rd)
? But then that would be more difficult for the user.
shuffler.h
#include <random>
class Shuffler
{
private:
std::random_device m_rd;
std::mt19937 m_gen;
public:
//! The default constructor.
Shuffler();
};
shuffler.cpp
#include "shuffler.h"
Shuffler::Shuffler() : m_gen(m_rd())
{
}
Aucun commentaire:
Enregistrer un commentaire