I'm doing tests on how to generate random numbers in C++ and in each execution I get exactly the same sequence,
#include <random>
#include <iostream>
int main() {
std::random_device device;
std::mt19937 generator(device());
std::uniform_int_distribution<int> distribution(1,100);
for(int i = 0; i < 10; i++) std::cout << distribution(generator) << " ";
}
I understood that with std::random_device I would get a pseudo-random seed for the generator, but it doesn't work as I expected. Are there any additional steps to be taken?
Aucun commentaire:
Enregistrer un commentaire