From 08a9a1cf41bdd5480bf6b5371e0b124c7834dcfa 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 | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/tests/impl.cpp b/tests/impl.cpp index 82b58b3c..d606fd1b 100644 --- a/tests/impl.cpp +++ b/tests/impl.cpp @@ -350,10 +350,34 @@ static inline double bankersRounding(double val) return ret; } -static float ranf(void) -{ - uint32_t ir = rand() & 0x7FFF; - return (float) ir * (1.0f / 32768.0f); +/* Written in 2015 by Sebastiano Vigna (vigna@acm.org) + * + * To the extent possible under law, the author has dedicated all copyright + * and related and neighboring rights to this software to the public domain + * worldwide. This software is distributed without any warranty. + * + * See . */ + +/* This is a fixed-increment version of Java 8's SplittableRandom generator + * See http://dx.doi.org/10.1145/2714064.2660195 and + * http://docs.oracle.com/javase/8/docs/api/java/util/SplittableRandom.html + * + * It is a very fast generator passing BigCrush, and it can be useful + * if for some reason you absolutely want 64 bits of state. */ +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() +{ + return next() / TWOPOWER64; } static float ranf(float low, float high)