Browse Source

Improved the numeric distribution of love.math.random.

--HG--
branch : minor
Alex Szpakowski 9 years ago
parent
commit
8b920ba816
1 changed files with 7 additions and 1 deletions
  1. 7 1
      src/modules/math/RandomGenerator.h

+ 7 - 1
src/modules/math/RandomGenerator.h

@@ -73,7 +73,13 @@ public:
 	 **/
 	 **/
 	inline double random()
 	inline double random()
 	{
 	{
-		return double(rand()) / (double(std::numeric_limits<uint64>::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;
 	}
 	}
 
 
 	/**
 	/**