Created
September 10, 2013 18:08
-
-
Save disjukr/6513238 to your computer and use it in GitHub Desktop.
lfsr113(PRNG) for javascript.
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
function LFSR113(a, b, c, d) { | |
if ((a |= 0) < 1) throw 'a must bigger than 1'; | |
if ((b |= 0) < 7) throw 'b must bigger than 7'; | |
if ((c |= 0) < 15) throw 'c must bigger than 15'; | |
if ((d |= 0) < 127) throw 'd must bigger than 127'; | |
this.next = function () { | |
var e = ((a << 6) ^ a) >> 13; | |
a = ((a & 4294967294) << 18) ^ e; | |
e = ((b << 2) ^ b) >> 27; | |
b = ((b & 4294967288) << 2) ^ e; | |
e = ((c << 13) ^ c) >> 21; | |
c = ((c & 4294967280) << 7) ^ e; | |
e = ((d << 3) ^ d) >> 12; | |
d = ((d & 4294967168) << 13) ^ e; | |
return (a ^ b ^ c ^ d) * 2.3283064365386963e-10 + 0.5; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment