Created
January 16, 2024 01:51
-
-
Save hsingtism/6cca92120440f2aaa5b7d6883c7fb0fa to your computer and use it in GitHub Desktop.
pseudorandom number generator I use sometimes
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
| // based on V8 https://v8.dev/blog/math-random. | |
| uint64_t state0 = 0x4D696B696E6C6579; | |
| uint64_t state1 = 0x0000004873696E67; | |
| uint64_t xorshift128plus() { | |
| uint64_t s1 = state0; | |
| uint64_t s0 = state1; | |
| state0 = s0; | |
| s1 ^= s1 << 23; | |
| s1 ^= s1 >> 17; | |
| s1 ^= s0; | |
| s1 ^= s0 >> 26; | |
| state1 = s1; | |
| return state0 + state1; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment