mardi 18 août 2015

Error in using mt19937 with random_device as static class members

I have a class called RandomNumberGenerator using which I want to generate a random number using mt19937 algorithm.

I am creating an object of random_device to work as seed.

When I compile, I am getting an error that says: "No member named generate in std::__1::random_device". I am not able to understand the error. Perhaps I am doing something wrong in the way I am initializing the objects of random_device and mt19937 but am unable to figure out what's wrong. Appreciate some help..

RandomNumberGenerator.h

class RandomNumberGenerator
{
    static std::random_device   m_rd;
    static std::mt19937         m_rng;
public:
    static double getRandomNumber(const double& rangeStart, const double& rangeEnd);
};

RandomNumberGenerator.cpp

#include "RandomNumberGenerator.h"

std::random_device   RandomNumberGenerator::m_rd;
std::mt19937         RandomNumberGenerator::m_rng(RandomNumberGenerator::m_rd);

double RandomNumberGenerator::getRandomNumber(const double& rangeStart, const double& rangeEnd)
{
    std::uniform_real_distribution<> randomizer(rangeStart, rangeEnd);
    return randomizer(m_rng);
}




Aucun commentaire:

Enregistrer un commentaire