From 3f8d5ebedf387495ece37dfe50288884768f6dfb Mon Sep 17 00:00:00 2001 From: Cuda-Chen Date: Tue, 25 Jul 2023 16:08:09 +0800 Subject: [PATCH] Use SplitMix64 for seeding test cases Close #581. --- tests/impl.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tests/impl.cpp b/tests/impl.cpp index 82b58b3c..cd16a2af 100644 --- a/tests/impl.cpp +++ b/tests/impl.cpp @@ -350,10 +350,21 @@ static inline double bankersRounding(double val) return ret; } -static float ranf(void) +// by Sebastiano Vigna, see: +static uint64_t x; +const double TWOPOWER64 = pow(2, 64); + +static double next() +{ + uint64_t z = (x += 0x9e3779b97f4a7c15); + z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9; + z = (z ^ (z >> 27)) * 0x94d049bb133111eb; + return z ^ (z >> 31); +} + +static float ranf() { - uint32_t ir = rand() & 0x7FFF; - return (float) ir * (1.0f / 32768.0f); + return next() / TWOPOWER64; } static float ranf(float low, float high)