From 8b920ba816ef5d7f0daf99914efc8638ffd4249f Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sun, 15 May 2016 10:25:08 -0300 Subject: [PATCH] Improved the numeric distribution of love.math.random. --HG-- branch : minor --- src/modules/math/RandomGenerator.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/modules/math/RandomGenerator.h b/src/modules/math/RandomGenerator.h index ce3b5b0d6..c6f93f29c 100644 --- a/src/modules/math/RandomGenerator.h +++ b/src/modules/math/RandomGenerator.h @@ -73,7 +73,13 @@ public: **/ inline double random() { - return double(rand()) / (double(std::numeric_limits::max()) + 1.0); + uint64 r = rand(); + + // From http://xoroshiro.di.unimi.it + union { uint64 i; double d; } u; + u.i = ((0x3FFULL) << 52) | (r >> 12); + + return u.d - 1.0; } /**