Skip to content

Instantly share code, notes, and snippets.

@607011
Created March 5, 2025 13:47
Show Gist options
  • Save 607011/2ee288dfdae0e8429b6b582250361647 to your computer and use it in GitHub Desktop.
Save 607011/2ee288dfdae0e8429b6b582250361647 to your computer and use it in GitHub Desktop.
xorshift128+
struct xorshift128p {
uint64_t x[2];
xorshift128p(uint64_t s1, uint64_t s2) {
x[0] = s1;
x[1] = s2;
}
xorshift128p(uint64_t s[2]) {
x[0] = s[0];
x[1] = s[1];
}
void seed(uint64_t s1, uint64_t s2) {
x[0] = s1;
x[1] = s2;
}
void seed(uint64_t s[2]) {
x[0] = s[0];
x[1] = s[1];
}
uint64_t rand_int(void)
{
uint64_t t = this->x[0];
uint64_t const s = this->x[1];
this->x[0] = s;
t ^= t << 23; // a
t ^= t >> 18; // b -- Again, the shifts and the multipliers are tunable
t ^= s ^ (s >> 5); // c
this->x[1] = t;
return t + s;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment