dimanche 13 mai 2018

Why C++

I tried to generate a sequence of uniformly distributed random numbers using C++ library. However, I already tried all of 10 generators but the result does not seem to be uniformly distributed.

My program is as follows:

typedef std::minstd_rand base_generator_type;

void udng(int* rnd, int rows, int cols, int start, int end) {
    base_generator_type generator;
    std::uniform_int_distribution<int> distribution(start, end);

    int i = rows*cols;
    for (; i--;)
        *(rnd+i) = distribution(generator);
}

The result when I tried to generate 2550 random numbers in the range [0, 255] is enter image description here

Could anyone give me a hint on what is wrong in my code?

Thanks!




Aucun commentaire:

Enregistrer un commentaire