Skip to content

Instantly share code, notes, and snippets.

@fumobox
Created June 7, 2014 13:37
Show Gist options
  • Save fumobox/54212cd613ae266c3346 to your computer and use it in GitHub Desktop.
Save fumobox/54212cd613ae266c3346 to your computer and use it in GitHub Desktop.
class Xorshift {
private var x:UInt;
private var y:UInt;
private var z:UInt;
private var w:UInt;
private var t:UInt;
public function new(x:UInt = 1234, y:UInt = 5678, z:UInt = 9876, w:UInt = 5432) {
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}
public function nextUInt():UInt {
t = x ^ (x << 11);
x = y;
y = z;
z = w;
return w = (w ^ (w >>> 19)) ^ (t ^ (t >>> 8));
}
public function nextFloat():Float {
t = x ^ (x << 11);
x = y;
y = z;
z = w;
w = (w ^ (w >>> 19)) ^ (t ^ (t >>> 8));
return w / 4294967295;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment