8 static inline uint64_t kr_splitmix64(uint64_t x
)
10 uint64_t z
= (x
+= 0x9E3779B97F4A7C15ULL
);
11 z
= (z
^ (z
>> 30)) * 0xBF58476D1CE4E5B9ULL
;
12 z
= (z
^ (z
>> 27)) * 0x94D049BB133111EBULL
;
16 static inline uint64_t kr_rand_r(krng_t
*r
)
18 const uint64_t s0
= r
->s
[0];
19 uint64_t s1
= r
->s
[1];
20 const uint64_t result
= s0
+ s1
;
22 r
->s
[0] = (s0
<< 55 | s0
>> 9) ^ s1
^ (s1
<< 14);
23 r
->s
[1] = s0
<< 36 | s0
>> 28;
27 static inline void kr_jump_r(krng_t
*r
)
29 static const uint64_t JUMP
[] = { 0xbeac0467eba5facbULL
, 0xd86b048b86aa9922ULL
};
30 uint64_t s0
= 0, s1
= 0;
32 for (i
= 0; i
< 2; ++i
)
33 for (b
= 0; b
< 64; b
++) {
34 if (JUMP
[i
] & 1ULL << b
)
35 s0
^= r
->s
[0], s1
^= r
->s
[1];
38 r
->s
[0] = s0
, r
->s
[1] = s1
;
41 static inline void kr_srand_r(krng_t
*r
, uint64_t seed
)
43 r
->s
[0] = kr_splitmix64(seed
);
44 r
->s
[1] = kr_splitmix64(r
->s
[0]);
47 static inline double kr_drand_r(krng_t
*r
)
49 union { uint64_t i
; double d
; } u
;
50 u
.i
= 0x3FFULL
<< 52 | kr_rand_r(r
) >> 12;