Skip to content

Instantly share code, notes, and snippets.

@lemon32767
Last active March 8, 2021 10:09
Show Gist options
  • Save lemon32767/bcd46f822d2434a17e003256ba4d9fa3 to your computer and use it in GitHub Desktop.
Save lemon32767/bcd46f822d2434a17e003256ba4d9fa3 to your computer and use it in GitHub Desktop.
16-bit seed PRNG. period=65534. uniform-ish looking distribution https://i.imgur.com/kKI5W2s.png
typedef unsigned short u16;
u16 random_u16(void) {
static u16 s;
s ^= s << 8;
s = ((s & 0xFF) << 1) ^ ((s << 8) | (s >> 8));
s = 38607*s + 35335;
s = (s >> 1) ^ (-(~s & 1) & 0x9E74) ^ 0x7E00;
return s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment