I want to use the library in my program and I will have classes with different distributions and I want to generate a number at different times in my program. Currently I have the following in my header file
#include <random>
#include <time.h>
class enemy {
private:
int max_roll;
typedef std::mt19937 MyRng;
MyRng rng;
public:
enemy(int MR){
max_roll = MR;
rng.seed(time(NULL));
std::uniform_int_distribution<int> dice(1, max_roll);
}
int roll() {
return dice(rng);
}
};
I'm getting the issue with 'dice' being undefined even though it's in my constructor there. It will work when I move my distribution definition to the beginning of my roll function, but when I do that, I get the same number every time I call it. I've tried following the answer on this question, but I couldn't work it out.
Aucun commentaire:
Enregistrer un commentaire