-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxoroshiro.h
33 lines (27 loc) · 874 Bytes
/
xoroshiro.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
* xoroshiro128_plus functions have the following copyright:
*
* Written in 2016-2018 by David Blackman and 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/>.
*/
#include <stdint.h>
extern void xoroshiro128plus_init(uint64_t *s, uint64_t seed);
static inline uint64_t
rotl(const uint64_t x, int k)
{
return (x << k) | (x >> (64 - k));
}
static inline uint64_t
xoroshiro128plus(uint64_t *s)
{
const uint64_t s0 = s[0];
uint64_t s1 = s[1];
const uint64_t result = s0 + s1;
s1 ^= s0;
s[0] = rotl(s0, 24) ^ s1 ^ (s1 << 16); // a, b
s[1] = rotl(s1, 37); // c
return result;
}