Skip to content

Instantly share code, notes, and snippets.

@hsingtism
Created January 16, 2024 01:51
Show Gist options
  • Select an option

  • Save hsingtism/6cca92120440f2aaa5b7d6883c7fb0fa to your computer and use it in GitHub Desktop.

Select an option

Save hsingtism/6cca92120440f2aaa5b7d6883c7fb0fa to your computer and use it in GitHub Desktop.
pseudorandom number generator I use sometimes
// 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