From 77aff4658bdbe6d34f2e3cc85c065e3ea91e9d78 Mon Sep 17 00:00:00 2001 From: ed Date: Mon, 27 Apr 2020 09:28:51 +0100 Subject: [PATCH] Fixed an edge case in Random::nextFloat() for dividends approaching std::numeric_limits::max() --- modules/juce_core/maths/juce_Random.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/juce_core/maths/juce_Random.cpp b/modules/juce_core/maths/juce_Random.cpp index 9cca2dc6ab..bd9e3994ed 100644 --- a/modules/juce_core/maths/juce_Random.cpp +++ b/modules/juce_core/maths/juce_Random.cpp @@ -105,7 +105,8 @@ bool Random::nextBool() noexcept float Random::nextFloat() noexcept { - return static_cast (nextInt()) / (std::numeric_limits::max() + 1.0f); + auto result = static_cast (nextInt()) / (std::numeric_limits::max() + 1.0f); + return result == 1.0f ? 1.0f - std::numeric_limits::epsilon() : result; } double Random::nextDouble() noexcept