https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64351
Bug ID: 64351 Summary: std::uniform_real_distribution<float>(0, 1) returns 1 Product: gcc Version: 3.3.6 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: info at jmeng dot de I'm seeing std::uniform_real_distribution<float>(0, 1) return 1 even though the standard seems to say it shouldn't: "A uniform_real_distribution random number distribution produces random numbers x, a ≤ x < b" (I looked at the draft available here: http://www.open-std.org/JTC1/SC22/WG21/ or specifically here: http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2011/n3242.pdf) There is a relatively minimal working example you can try here: http://coliru.stacked-crooked.com/a/4ca5b4ac05e990ff Or, if you prefer to see the code directly: // This program outputs 1, but uniform_real_distribution is supposed // to return values in [0, 1) (the half open interval). #include <random> #include <cstdint> #include <iostream> int main() { std::mt19937 rng(8890); std::uniform_real_distribution<float> dist; uint64_t num_1 = 0; for (uint64_t i = 0; i < 39975715; ++i) { if (dist(rng) == 1.f) ++num_1; } std::cout << num_1 << std::endl; return 0; } Note that there is a related note in this bug report: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43660#c2