samedi 19 août 2017

std::random_device not working in g++

I'm using g++ to compile my c++ code, which looks like this:

std::mt19937_64 rng(std::random_device{}());
std::uniform_int_distribution<int> dist(0, words.size() - 1);
std::string curr = words[dist(rng)];

as you can see, this extracts a random word from an array of std::string, but when I optput that word, its always the same, i've realised that the problem lies in std::random_device, which outputs always the same number.

why is this happening? how can I fix it?




Aucun commentaire:

Enregistrer un commentaire