Skip to content

Instantly share code, notes, and snippets.

@disjukr
Created September 10, 2013 18:08
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 disjukr/6513238 to your computer and use it in GitHub Desktop.
Save disjukr/6513238 to your computer and use it in GitHub Desktop.
lfsr113(PRNG) for javascript.
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