Namespaces
Variants
Views
Actions

Talk:cpp/numeric/random/uniform real distribution

From cppreference.com

[edit] Range Limitations

I've encountered this limitation when attempting to produce a distribution in the range [std::numeric_limits<RealType>::lowest(), std::numeric_limits<RealType>::max()). Confused as to why my application was always returning infinity I started researching uniform_real_distribution. No documentation I could find (other than the standard itself) stated anything about a limit on the range. Eventually I did find that the standard does say that it requires a ≤ b and b − a ≤ numeric_limits<RealType>::max(). This requirement was obtained from n3242 the final draft version for C++11 and is still present in N4594 the latest draft version for C++17.

Should this limitation be added to the page? --Bamakid (talk) 11:27, 6 July 2016 (PDT)

it's already here in the description of the constructor std::uniform_real_distribution::uniform_real_distribution under Notes --Cubbi (talk) 11:42, 6 July 2016 (PDT)
Ah, thanks. Is there a reason for it to not be on the class's page? After all, it states "...uniformly distributed on the interval [a, b)" leaving readers to believe it will work from lowest() to max(), unless they are quick enough to understand that b-a will cause a problem. --Bamakid (talk) 12:49, 6 July 2016 (PDT)

The std from Microsoft Visual Studio 14.0 can also returns the upperbound in this case: I got exactly 1.0f returned from std::uniform_real_distribution<float>(0.0f, 1.0f). 109.15.56.2 05:47, 26 March 2021 (PDT)Tristan

Added to the list in cpp/numeric/random/uniform_real_distribution#Notes. --Fruderica (talk) 07:15, 26 March 2021 (PDT)