Comparing version 1.1.0 to 1.1.1
{ | ||
"name": "xorshift", | ||
"description": "Random number generator using xorshift128+", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"author": "Andreas Madsen <amwebdk@gmail.com>", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -94,30 +94,7 @@ | ||
*/ | ||
var CONVERTION_BUFFER = new Buffer(8); | ||
XorShift.prototype.random = function() { | ||
// :: t2 = randomint() | ||
var t2 = this.randomint(); | ||
var t2U = t2[0]; | ||
var t2L = t2[1]; | ||
// :: e = UINT64_C(0x3FF) << 52 | ||
var eU = 0x3FF << (52 - 32); | ||
var eL = 0; | ||
// :: s = t2 >> 12 | ||
var a1 = 12; | ||
var m1 = 0xFFFFFFFF >>> (32 - a1); | ||
sU = t2U >>> a1; | ||
sL = (t2L >>> a1) | ((t2U & m1) << (32 - a1)); | ||
// :: x = e | s | ||
var xU = eU | sU; | ||
var xL = eL | sL; | ||
// :: double d = *((double *)&x) | ||
CONVERTION_BUFFER.writeUInt32BE(xU, 0, true); | ||
CONVERTION_BUFFER.writeUInt32BE(xL, 4, true); | ||
var d = CONVERTION_BUFFER.readDoubleBE(0, true); | ||
// :: d - 1 | ||
return d - 1; | ||
// Math.pow(2, -32) = 2.3283064365386963e-10 | ||
// Math.pow(2, -52) = 2.220446049250313e-16 | ||
return t2[0] * 2.3283064365386963e-10 + (t2[1] >>> 12) * 2.220446049250313e-16; | ||
}; | ||
@@ -124,0 +101,0 @@ |
25900
618