UNPKG

alea-generator

Version:

A performant and effective random number generator

3 lines (2 loc) 1.09 kB
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t||self).aleaGenerator={})}(this,function(t){var n=Number.EPSILON/2,e=4294967296,r=Math.pow(2,-32),o=function(t){void 0===t&&(t=""+Date.now());var o=function(){var t=4022871197;return function(n){for(var o=n.toString(),f=0;f<o.length;f++){var u=.02519603282416938*(t+=o.charCodeAt(f));u-=t=u>>>0,t=(u*=t)>>>0,t+=(u-=t)*e}return(t>>>0)*r}}(),f=[o(" "),o(" "),o(" "),1];f[0]-=o(t),f[0]<0&&(f[0]+=1),f[1]-=o(t),f[1]<0&&(f[1]+=1),f[2]-=o(t),f[2]<0&&(f[2]+=1);var u={random:function(){var t=2091639*f[0]+f[3]*r;return f[0]=f[1],f[1]=f[2],f[2]=t-(f[3]=Math.floor(t))},uint32:function(){return u.random()*e},fract53:function(){return u.random()+Math.trunc(2097152*u.random())*n},exportState:function(){return{seed0:f[0],seed1:f[1],seed2:f[2],constant:f[3]}},importState:function(t){var n=[t.seed0,t.seed1,t.seed2,t.constant];f[0]=n[0],f[1]=n[1],f[2]=n[2],f[3]=n[3]}};return u},f=o().random;t.alea=f,t.aleaFactory=o}); //# sourceMappingURL=alea.umd.js.map