Created
June 7, 2014 13:37
-
-
Save fumobox/54212cd613ae266c3346 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
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