jeudi 16 mai 2019

Getting the same set of random numbers on every run. (using both int and real uniform distribution)

On every run the same set of numbers are generated. I am not sure Why it is happening. is there any other way to generate the random numbers using random library that prevents this bug ? or is there anything wrong with my compiler or program ?

#include <iostream>
#include <random>

float get_random() {
    static std::default_random_engine random;
    std::uniform_real_distribution<> distribution{0, 1};

    return distribution(random);
}

int main() {
    for (size_t i = 0; i < 10; i++) {
        std::cout<<get_random()<<std::endl;
    }

    return 0;
}




Aucun commentaire:

Enregistrer un commentaire