mardi 17 mars 2020

std::mt19937 generator returns the same values each execution, why?

How can my program generate different random numbers each execution?

I'm trying to do the following program

#include <random>
#include <iostream>

int main()
{
    std::random_device rd;
    std::mt19937 gen(rd());
    std::uniform_int_distribution<> dis(1, 100);

    //Matrix 8x4 size declaration
    int16_t **mtr = new int16_t*[8];
    for (size_t i = 0; i < 8; i++) {
        mtr[i] = new int16_t[4];
        for (size_t j = 0; j < 4; j++)
            mtr[i][j] = dis(gen);
    }
    //... more code
}

All works fine, BUT each time I execute this program, the generated numbers are the same. I tried with the <ctime> library and it worked (I know It is unsecure...)

Note: With execution I mean each time I call the executable file




Aucun commentaire:

Enregistrer un commentaire