samedi 8 mai 2021

how to generate a random seed with

I'm using this code to generate some random integers:

#include <random>

std::random_device rd; // obtain a random number from hardware
std::mt19937 gen(rd()); // seed the generator
std::uniform_int_distribution<> distr(-10, 10); // define the range

for(int i = 0; i < 20; i++){
    std::cout << distr(gen) << ' '; // generate numbers
}

This works, but the numbers are always the same so i think something is wrong with the seed.




Aucun commentaire:

Enregistrer un commentaire