diff options
Diffstat (limited to 'src/util/rand_xor.c')
-rw-r--r-- | src/util/rand_xor.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/util/rand_xor.c b/src/util/rand_xor.c new file mode 100644 index 0000000000..07b4c22ee1 --- /dev/null +++ b/src/util/rand_xor.c @@ -0,0 +1,20 @@ +#include "rand_xor.h" + +/* Super fast random number generator. + * + * This rand_xorshift128plus function by Sebastiano Vigna belongs + * to the public domain. + */ +uint64_t +rand_xorshift128plus(uint64_t *seed) +{ + uint64_t *s = seed; + + uint64_t s1 = s[0]; + const uint64_t s0 = s[1]; + s[0] = s0; + s1 ^= s1 << 23; + s[1] = s1 ^ s0 ^ (s1 >> 18) ^ (s0 >> 5); + + return s[1] + s0; +} |