Skip to content

Instantly share code, notes, and snippets.

@rygorous
Created November 16, 2015 05:23
Embed
What would you like to do?
Somewhat better unxorshift
uint64_t unxorshift(uint64_t xs, uint32_t shamt)
{
// NB shamt >= 1 required; shamt=0 is not reversible for obvious reasons :)
// I am still convinced there's a much tighter way to code this, but this one
// is less terrible.
uint64_t x = xs;
for (uint32_t k = 32; k >= 1; k >>= 1)
{
uint32_t l = k * shamt;
if (l < 64)
x ^= x >> l;
}
return x;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment