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) • 1.55 kB
JavaScript
;function r(r,n){return(65535&(r|=0))*(n|=0)+(((r>>>16)*n&65535)<<16)|0}function n(r,n){return r[n++]+(r[n++]<<8)+(r[n++]<<16)+(r[n++]<<24)}function t(r){if(void 0!==r&&r%1!=0)throw new TypeError("Expected seed to be an integer, float given")}function e(r,n){if("string"!=typeof r)throw new TypeError("".concat(n,"(): first argument is not a string."))}function i(r){for(var n=r.length,t=-1,e=new Uint8Array(3*n),i=0;i!==n;){var o=r.charCodeAt(i);if(i+=1,o>=55296&&o<=56319){if(i===n){e[t+=1]=239,e[t+=1]=191,e[t+=1]=189;break}var a=r.charCodeAt(i);if(!(a>=56320&&a<=57343)){e[t+=1]=239,e[t+=1]=191,e[t+=1]=189;continue}if(i+=1,(o=1024*(o-55296)+a-56320+65536)>65535){e[t+=1]=240|o>>>18,e[t+=1]=128|o>>>12&63,e[t+=1]=128|o>>>6&63,e[t+=1]=128|63&o;continue}}o<=127?e[t+=1]=0|o:o<=2047?(e[t+=1]=192|o>>>6,e[t+=1]=128|63&o):(e[t+=1]=224|o>>>12,e[t+=1]=128|o>>>6&63,e[t+=1]=128|63&o)}return e.subarray(0,t+1)}function o(r){for(var n=new Uint8Array(r.length),t=0;t<r.length;t+=1){var e=r.charCodeAt(t);if(e<0||e>127)return i(r);n[t]=e}return n}var a,u,c=(a=1540483477,u=function(r,n){return r[n++]+(r[n]<<8)},function(i){var c=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;e(i,"murmurhash2_x86_32"),t(c);for(var f=o(i),h=0,s=c^f.length,v=f.length;v>=4;){var g=n(f,h);g=r(g,a),g=r(g^=g>>>24,a),s=r(s,a),s^=g,h+=4,v-=4}switch(v){case 3:s^=u(f,h),s=r(s^=f[h+2]<<16,a);break;case 2:s=r(s^=u(f,h),a);break;case 1:s=r(s^=f[h],a)}return s=r(s^=s>>>13,a),(s^=s>>>15)>>>0});module.exports=c;
//# sourceMappingURL=murmurhash2_x86_32.js.map