Skip to content

Commit

Permalink
Use SplitMix64 for seeding test cases
Browse files Browse the repository at this point in the history
Close #581.
  • Loading branch information
Cuda-Chen committed Oct 6, 2023
1 parent 8371b36 commit 08a9a1c
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions tests/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ([email protected])
*
* 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 <http://creativecommons.org/publicdomain/zero/1.0/>. */

/* 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)
Expand Down

0 comments on commit 08a9a1c

Please sign in to comment.