From 5c5f3f45171e649754da1069b4fa03c883d5d53b Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Thu, 31 Oct 2019 17:25:52 -0400 Subject: [PATCH] Fix random::uniform() to not return 1.f. --- src/random.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/random.cpp b/src/random.cpp index fc692e35..2c37b39d 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -49,8 +49,7 @@ uint64_t u64() { } float uniform() { - // 24 bits of granularity is the best that can be done with floats while ensuring that the return value lies in [0.0, 1.0). - return xoroshiro128plus_next() / std::pow(2.f, 64); + return (xoroshiro128plus_next() >> (64 - 24)) / std::pow(2.f, 24); } float normal() {