Skip to content

Instantly share code, notes, and snippets.

@Marc-B-Reynolds
Last active December 7, 2016 10:40
Show Gist options
  • Save Marc-B-Reynolds/80ceaf0b4724ad428d86d7c025d0d9ad to your computer and use it in GitHub Desktop.
Save Marc-B-Reynolds/80ceaf0b4724ad428d86d7c025d0d9ad to your computer and use it in GitHub Desktop.
2x32-bit xorshift/weyl sequence
// 1 dep-chain (assuming state words in reg) to result.
// DON'T USE ME UNLESS YOUR PARINOID AND
// USING SOMETHING MORE EXPENSIVE (actually inferior
// to some other formulations...period is only 2^32-1)
// Zero is illegal for both state words.
typedef struct { uint32_t s[2]; } rng_state_t;
// smallcrush: passes
// crush: 1 systematic failure = 72 LinearComp, r = 29
static inline uint32_t rng_u32(rng_state_t* s)
{
uint32_t x = s->s[1];
uint32_t r = s->s[0] + x;
s->s[0] = x * 1597334677;
x ^= (x << 13);
x ^= (x >> 17);
x ^= (x << 5);
s->s[1] = x;
return r;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment