[C++] Random number generator crashes with normal distribution

#1
Goooooood morning!

I'm trying to tackle an issue with my module that bugs me for quite some time now. I implemented a simple RNG that I use throughout my code. II encapsulated the RNG into a global class that I reference whenever I need it. This is the declaration:

C++:
#include <random>

class Rng {
private:
    std::mt19937 generator;
    std::random_device rd;
public:
    Rng();
    ~Rng();

    bool getRandomBool();
    bool getRandomBool(const double probability);
    int getRandomInt(const int min, const int max);
    double getRandomDouble(const double min, const double max);

    double getNormalDouble(const double mean, const double sigma);
};

extern Rng rng;
Here's the constructor of my Rng class:
C++:
Rng::Rng()
{
    generator.seed(rd());
}
But ever since the beginning of this, I'm having trouble implementing the normal distribution function getNormalDouble. This is what I try to do:
C++:
//Returns a double value, based on a normal distribution
double Rng::getNormalDouble(const double mean, const double sigma) {
    normal_distribution<> normal_distr(mean, sigma);

    return normal_distr(generator);
}
But when I try running the code I get this strange crash:


Any idea what might cause this?
 
#3
Interesting... I remember years ago, you were working on a random number 'something' way back then. I thought Bill Leaming compared it to the Random 'somewhere' Drive from that science fiction series where you must carry a hand towel with you everywhere through the Universe, looking for the best restaurant?

Hope you get it working. I so need to learn C++... So much more is capable in that.
 
#5
Thanks for the replies guys!

Ron,
I tried that as well. No change.

Bill,
Did I asked this question before? That must've been ages ago though. I better not start digging up my old posts, that's too embarrassing :laughing:

You should give C++ a shot. Best for you to start with something you could've done in XML as well, to keep it simple.
 
#6
Bill,

You should give C++ a shot. Best for you to start with something you could've done in XML as well, to keep it simple.
Roger that and will do. As soon as I launch this one, I'll do that tutorial gauge or something similar.

Hope you get your numbers working.
 
Top