Created
July 24, 2022 10:37
-
-
Save barncastle/0fb2279bdc337d2a7d951e1bd2e3c0df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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