-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use SplitMix64 for seeding test cases
Close #581.
- Loading branch information
Showing
1 changed file
with
28 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|