UNPKG

alea-generator

Version:

A performant and effective random number generator

3 lines (2 loc) 919 B
var n=Number.EPSILON/2,r=Math.pow(2,-32),t=function(t){void 0===t&&(t=""+Date.now());var e=function(){var n=4022871197;return function(t){t=t.toString();for(var e=0;e<t.length;e++){var o=.02519603282416938*(n+=t.charCodeAt(e));o-=n=o>>>0,n=(o*=n)>>>0,n+=4294967296*(o-=n)}return(n>>>0)*r}}(),o=[e(" "),e(" "),e(" "),1];o[0]-=e(t),o[0]<0&&(o[0]+=1),o[1]-=e(t),o[1]<0&&(o[1]+=1),o[2]-=e(t),o[2]<0&&(o[2]+=1);var a={random:function(){var n=2091639*o[0]+o[3]*r;return o[0]=o[1],o[1]=o[2],o[2]=n-(o[3]=Math.floor(n))},uint32:function(){return 4294967296*a.random()},fract53:function(){return a.random()+Math.trunc(2097152*a.random())*n},exportState:function(){return{seed0:o[0],seed1:o[1],seed2:o[2],constant:o[3]}},importState:function(n){var r=[n.seed0,n.seed1,n.seed2,n.constant];o[0]=r[0],o[1]=r[1],o[2]=r[2],o[3]=r[3]}};return a},e=t().random;export{e as alea,t as aleaFactory}; //# sourceMappingURL=alea.module.js.map