Skip to content

Instantly share code, notes, and snippets.

@barncastle
Created July 24, 2022 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barncastle/0fb2279bdc337d2a7d951e1bd2e3c0df to your computer and use it in GitHub Desktop.
Save barncastle/0fb2279bdc337d2a7d951e1bd2e3c0df to your computer and use it in GitHub Desktop.
public class WELL512
{
private readonly uint[] State;
private int Index;
public WELL512(uint seed)
{
Index = 0;
State = new uint[16];
SetSeed(seed);
}
private void SetSeed(uint seed)
{
Index = 0;
State[0] = seed;
for (var i = 1u; i < 0x10; i++)
State[i] = i + 0x6C078965 * (State[i - 1] ^ (State[i - 1] >> 30));
}
public uint NextUInt()
{
uint a, b, c, d;
a = State[Index];
c = State[(Index + 13) & 15];
b = a ^ c ^ (a << 16) ^ (c << 15);
c = State[(Index + 9) & 15];
c ^= c >> 11;
a = State[Index] = b ^ c;
d = a ^ ((a << 5) & 0xDA442D24);
Index = (Index + 15) & 15;
a = State[Index];
State[Index] = a ^ b ^ d ^ (a << 2) ^ (b << 18) ^ (c << 28);
return State[Index];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment