lundi 16 mars 2020

std::normal_distribution as member variable in C++

I have a random generator wrapper class.

    class mt19937NormalRng {
    public:
        mt19937NormalRng(unsigned int seed = 0)
            : rd(), gen(seed), engine(0.0, 1.0) {}
        double next() const {
            return engine(gen);
        }
    private:
        std::random_device rd;
        std::mt19937_64 gen;
        std::normal_distribution<double> engine;
    };

This code is not compiled.

Visual C++ compiler said engine is const std::normal_distribution<double>.

Is there a specific way to use std::normal_distribution in class?




Aucun commentaire:

Enregistrer un commentaire