Skip to content

Instantly share code, notes, and snippets.

@chiro-hiro
Created September 14, 2020 08:20
Show Gist options
  • Save chiro-hiro/bdf2198e50d6dbca310f1d6e34b3db5a to your computer and use it in GitHub Desktop.
Save chiro-hiro/bdf2198e50d6dbca310f1d6e34b3db5a to your computer and use it in GitHub Desktop.
#include <stdint.h>
struct xorshift128p_state {
uint64_t a, b;
};
/* The state must be seeded so that it is not all zero */
uint64_t xorshift128p(struct xorshift128p_state *state)
{
uint64_t t = state->a;
uint64_t const s = state->b;
state->a = s;
t ^= t << 23; // a
t ^= t >> 17; // b
t ^= s ^ (s >> 26); // c
state->b = t;
return t + s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment