07b4c22ee15a7f1cc2a17137bf495847d73d327b
[mesa.git] / src / util / rand_xor.c
1 #include "rand_xor.h"
2
3 /* Super fast random number generator.
4 *
5 * This rand_xorshift128plus function by Sebastiano Vigna belongs
6 * to the public domain.
7 */
8 uint64_t
9 rand_xorshift128plus(uint64_t *seed)
10 {
11 uint64_t *s = seed;
12
13 uint64_t s1 = s[0];
14 const uint64_t s0 = s[1];
15 s[0] = s0;
16 s1 ^= s1 << 23;
17 s[1] = s1 ^ s0 ^ (s1 >> 18) ^ (s0 >> 5);
18
19 return s[1] + s0;
20 }