Created
March 5, 2025 13:47
-
-
Save 607011/2ee288dfdae0e8429b6b582250361647 to your computer and use it in GitHub Desktop.
xorshift128+
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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