UNPKG

number-generator

Version:

Generate repeatable pseudo random numbers and non-cryptographic hash numbers for usage in Node.js and browser environments.

3 lines (2 loc) 8.13 kB
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).numberGenerator={})}(this,(function(e){"use strict";function r(e,r){return function(e){if(Array.isArray(e))return e}(e)||function(e,r){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==n)return;var t,a,u=[],o=!0,c=!1;try{for(n=n.call(e);!(o=(t=n.next()).done)&&(u.push(t.value),!r||u.length!==r);o=!0);}catch(e){c=!0,a=e}finally{try{o||null==n.return||n.return()}finally{if(c)throw a}}return u}(e,r)||function(e,r){if(!e)return;if("string"==typeof e)return n(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);"Object"===t&&e.constructor&&(t=e.constructor.name);if("Map"===t||"Set"===t)return Array.from(e);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return n(e,r)}(e,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function n(e,r){(null==r||r>e.length)&&(r=e.length);for(var n=0,t=new Array(r);n<r;n++)t[n]=e[n];return t}function t(e,r){return(65535&(e|=0))*(r|=0)+(((e>>>16)*r&65535)<<16)|0}function a(e,r){return e[r++]+(e[r++]<<8)+(e[r++]<<16)+(e[r++]<<24)}function u(e){return e=t(e^=e>>>16,2246822507),e=t(e^=e>>>13,3266489909),e^=e>>>16}function o(e,r){return e<<r|e>>>32-r}function c(e){var n=r(e,4),t=n[0],a=n[1],u=n[2],o=n[3],c="00000000";return(c+(t>>>0).toString(16)).slice(-8)+(c+(a>>>0).toString(16)).slice(-8)+(c+(u>>>0).toString(16)).slice(-8)+(c+(o>>>0).toString(16)).slice(-8)}function i(e){if(void 0!==e&&e%1!=0)throw new TypeError("Expected seed to be an integer, float given")}function s(e,r){if("string"!=typeof e)throw new TypeError("".concat(r,"(): first argument is not a string."))}function f(e){for(var r=e.length,n=-1,t=new Uint8Array(3*r),a=0;a!==r;){var u=e.charCodeAt(a);if(a+=1,u>=55296&&u<=56319){if(a===r){t[n+=1]=239,t[n+=1]=191,t[n+=1]=189;break}var o=e.charCodeAt(a);if(!(o>=56320&&o<=57343)){t[n+=1]=239,t[n+=1]=191,t[n+=1]=189;continue}if(a+=1,(u=1024*(u-55296)+o-56320+65536)>65535){t[n+=1]=240|u>>>18,t[n+=1]=128|u>>>12&63,t[n+=1]=128|u>>>6&63,t[n+=1]=128|63&u;continue}}u<=127?t[n+=1]=0|u:u<=2047?(t[n+=1]=192|u>>>6,t[n+=1]=128|63&u):(t[n+=1]=224|u>>>12,t[n+=1]=128|u>>>6&63,t[n+=1]=128|63&u)}return t.subarray(0,n+1)}function l(e){for(var r=new Uint8Array(e.length),n=0;n<e.length;n+=1){var t=e.charCodeAt(n);if(t<0||t>127)return f(e);r[n]=t}return r}var h,g,v,d,m,y,p,b=(h=Math.pow(2,-32),g=Math.pow(2,32),function(e){var r=1,n=0,t=0,a=0;function u(e){return function(e){if(e%1!=0||e<=0)throw new TypeError('Expected seed to be an unsigned integer greater or equal 1, but got "'.concat(e,'"'))}(e),n=(e>>>0)*h,t=(e=69069*e+1>>>0)*h,a=(e=69069*e+1>>>0)*h,r=1,e}function o(){var e=2091639*n+r*h;return n=t,t=a,a=e-(r=0|e)}return u(void 0===e?1:e),{setSeed:u,uFloat32:o,uInt32:function(){return o()*g>>>0},getState:function(){return{correction:r,sequence:[n,t,a]}},setState:function(e){(e=e||{correction:1,sequence:[0,0,0]}).sequence=e.sequence||[],r=e.correction||1,n=e.sequence[0]||0,t=e.sequence[1]||0,a=e.sequence[2]||0}}}),w=(v=1540483477,d=function(e,r){return e[r++]+(e[r]<<8)},function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;s(e,"murmurhash2_x86_32"),i(r);for(var n=l(e),u=0,o=r^n.length,c=n.length;c>=4;){var f=a(n,u);f=t(f,v),f=t(f^=f>>>24,v),o=t(o,v),o^=f,u+=4,c-=4}switch(c){case 3:o^=d(n,u),o=t(o^=n[u+2]<<16,v);break;case 2:o=t(o^=d(n,u),v);break;case 1:o=t(o^=n[u],v)}return o=t(o^=o>>>13,v),(o^=o>>>15)>>>0}),_=(m=3432918353,y=461845907,p=3864292196,function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;s(e,"murmurhash3_x86_32"),i(r);for(var n=l(e),c=n.length%4,f=n.length-c,h=0,g=0,v=r;g<f;)h=t(h=a(n,g),m),h=t(h=o(h,15),y),v=t(v=o(v^=h,13),5)+p,g+=4;switch(h=0,c){case 3:h^=(255&n[g+2])<<16;case 2:h^=(255&n[g+1])<<8;case 1:h=t(h^=n[g],m),v^=h=t(h=o(h,15),y)}return(v=u(v^=n.length))>>>0}),x=function(){var e=597399067,r=2869860233,n=951274213,a=2716044179,f=1444728091,h=197830471,g=2530024501,v=850148119;return function(d){var m=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;s(d,"murmurhash3_x86_128"),i(m);for(var y=l(d),p=y.length%16,b=y.length-p,w=m,_=m,x=m,S=m,A=0,q=0,E=0,T=0,j=0;j<b;)A=255&y[j]|(255&y[j+1])<<8|(255&y[j+2])<<16|(255&y[j+3])<<24,q=255&y[j+4]|(255&y[j+5])<<8|(255&y[j+6])<<16|(255&y[j+7])<<24,E=255&y[j+8]|(255&y[j+9])<<8|(255&y[j+10])<<16|(255&y[j+11])<<24,T=255&y[j+12]|(255&y[j+13])<<8|(255&y[j+14])<<16|(255&y[j+15])<<24,A=o(A=t(A,e),15),w=o(w^=A=t(A,r),19),w=t(w+=_,5)+f,q=o(q=t(q,r),16),_=o(_^=q=t(q,n),17),_=t(_+=x,5)+h,E=o(E=t(E,n),17),x=o(x^=E=t(E,a),15),x=t(x+=S,5)+g,T=o(T=t(T,a),18),S=o(S^=T=t(T,e),13),S=t(S+=w,5)+v,j+=16;switch(A=0,q=0,E=0,T=0,p){case 15:T^=y[j+14]<<16;case 14:T^=y[j+13]<<8;case 13:T=t(T^=y[j+12],a),S^=T=t(T=o(T,18),e);case 12:E^=y[j+11]<<24;case 11:E^=y[j+10]<<16;case 10:E^=y[j+9]<<8;case 9:E=t(E^=y[j+8],n),x^=E=t(E=o(E,17),a);case 8:q^=y[j+7]<<24;case 7:q^=y[j+6]<<16;case 6:q^=y[j+5]<<8;case 5:q=t(q^=y[j+4],r),_^=q=t(q=o(q,16),n);case 4:A^=y[j+3]<<24;case 3:A^=y[j+2]<<16;case 2:A^=y[j+1]<<8;case 1:A=t(A^=y[j],e),w^=A=t(A=o(A,15),r)}return w^=y.length,w+=_^=y.length,w+=x^=y.length,_+=w+=S^=y.length,x+=w,S+=w,w=u(w),w+=_=u(_),w+=x=u(x),c([w+=S=u(S),_+=w,x+=w,S+=w])}}(),S=function(){var e=[2277735313,289559509],r=[1291169091,658871167],n=65535;function t(e,r){var t=[0,0,0,0];return e=[e[0]>>>16,e[0]&n,e[1]>>>16,e[1]&n],r=[r[0]>>>16,r[0]&n,r[1]>>>16,r[1]&n],t[3]+=e[3]*r[3],t[2]+=t[3]>>>16,t[3]&=n,t[2]+=e[2]*r[3],t[1]+=t[2]>>>16,t[2]&=n,t[2]+=e[3]*r[2],t[1]+=t[2]>>>16,t[2]&=n,t[1]+=e[1]*r[3],t[0]+=t[1]>>>16,t[1]&=n,t[1]+=e[2]*r[2],t[0]+=t[1]>>>16,t[1]&=n,t[1]+=e[3]*r[1],t[0]+=t[1]>>>16,t[1]&=n,t[0]+=e[0]*r[3]+e[1]*r[2]+e[2]*r[1]+e[3]*r[0],t[0]&=n,[t[0]<<16|t[1],t[2]<<16|t[3]]}function a(e,r){var t=[0,0,0,0];return e=[e[0]>>>16,e[0]&n,e[1]>>>16,e[1]&n],r=[r[0]>>>16,r[0]&n,r[1]>>>16,r[1]&n],t[3]+=e[3]+r[3],t[2]+=t[3]>>>16,t[3]&=n,t[2]+=e[2]+r[2],t[1]+=t[2]>>>16,t[2]&=n,t[1]+=e[1]+r[1],t[0]+=t[1]>>>16,t[1]&=n,t[0]+=e[0]+r[0],t[0]&=n,[t[0]<<16|t[1],t[2]<<16|t[3]]}function u(e,r){return(r%=64)<32?[e[0]<<r|e[1]>>>32-r,e[1]<<r|e[0]>>>32-r]:(r-=32,[e[1]<<r|e[0]>>>32-r,e[0]<<r|e[1]>>>32-r])}function o(e,r){return(r%=64)<32?[e[0]<<r|e[1]>>>32-r,e[1]<<r]:[e[1]<<r-32,0]}function f(e,r){return[e[0]^r[0],e[1]^r[1]]}function h(e){return e=f(e,[0,e[0]>>>1]),e=f(e=t(e,[4283543511,3981806797]),[0,e[0]>>>1]),e=f(e=t(e,[3301882366,444984403]),[0,e[0]>>>1])}return function(n){var g=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;s(n,"murmurhash3_x64_128"),i(g);for(var v=l(n),d=v.length%16,m=v.length-d,y=[0,g],p=[0,g],b=[0,0],w=[0,0],_=0;_<m;)b=[255&v[_+4]|(255&v[_+5])<<8|(255&v[_+6])<<16|(255&v[_+7])<<24,255&v[_]|(255&v[_+1])<<8|(255&v[_+2])<<16|(255&v[_+3])<<24],w=[255&v[_+12]|(255&v[_+13])<<8|(255&v[_+14])<<16|(255&v[_+15])<<24,255&v[_+8]|(255&v[_+9])<<8|(255&v[_+10])<<16|(255&v[_+11])<<24],b=u(b=t(b,e),31),y=a(y=u(y=f(y,b=t(b,r)),27),p),y=a(t(y,[0,5]),[0,1390208809]),w=u(w=t(w,r),33),p=a(p=u(p=f(p,w=t(w,e)),31),y),p=a(t(p,[0,5]),[0,944331445]),_+=16;switch(b=[0,0],w=[0,0],d){case 15:w=f(w,o([0,v[_+14]],48));case 14:w=f(w,o([0,v[_+13]],40));case 13:w=f(w,o([0,v[_+12]],32));case 12:w=f(w,o([0,v[_+11]],24));case 11:w=f(w,o([0,v[_+10]],16));case 10:w=f(w,o([0,v[_+9]],8));case 9:w=t(w=f(w,[0,v[_+8]]),r),p=f(p,w=t(w=u(w,33),e));case 8:b=f(b,o([0,v[_+7]],56));case 7:b=f(b,o([0,v[_+6]],48));case 6:b=f(b,o([0,v[_+5]],40));case 5:b=f(b,o([0,v[_+4]],32));case 4:b=f(b,o([0,v[_+3]],24));case 3:b=f(b,o([0,v[_+2]],16));case 2:b=f(b,o([0,v[_+1]],8));case 1:b=t(b=f(b,[0,v[_]]),e),y=f(y,b=t(b=u(b,31),r))}return y=a(y=f(y,[0,v.length]),p=f(p,[0,v.length])),p=a(p,y),y=a(y=h(y),p=h(p)),p=a(p,y),c([y[0],y[1],p[0],p[1]])}}();e.aleaRNGFactory=b,e.murmurhash2_x86_32=w,e.murmurhash3_x64_128=S,e.murmurhash3_x86_128=x,e.murmurhash3_x86_32=_,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=index.js.map