jeudi 2 février 2017

Can I pass a signed seed to std::mersenne_twister_engine

Consider

auto ms = std::chrono::duration_cast<std::chrono::milliseconds>
          (std::chrono::system_clock::now().time_since_epoch()).count();
std::mt19937 rd {ms};

ms is of type std::chrono::system_clock::rep which is signed. std::mt19937 will call std::mersenne_twister_engine(ms) but its parameter type result_type is unsigned.

Is there an issue with this? cppreference says it is undefined:

result_type | The integral type generated by the engine. Results are undefined if this is not an unsigned integral type.




Aucun commentaire:

Enregistrer un commentaire