lundi 29 mars 2021

std::uniform_real_distribution always returns infinity

When I run this code:

double getRandomDouble() {
    static std::mt19937 entropy_ = std::mt19937();
    std::uniform_real_distribution<double> distribution;
    distribution.param(typename decltype(distribution)::param_type(std::numeric_limits<double>::lowest(),
                                                                   std::numeric_limits<double>::max()));
    return distribution(entropy_);
}

It always returns infinity (at least in GCC8.1 & clang 11.0.1. In MSVC 14.16.27023 it asserts)

Here is a working demonstration in GodBolt

I would expect this function to return any random double value, what is happening here?




Aucun commentaire:

Enregistrer un commentaire