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.65 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(n){return n=r(n^=n>>>16,2246822507),n=r(n^=n>>>13,3266489909),n^=n>>>16}function e(r,n){return r<<n|r>>>32-n}function i(r){if(void 0!==r&&r%1!=0)throw new TypeError("Expected seed to be an integer, float given")}function o(r,n){if("string"!=typeof r)throw new TypeError("".concat(n,"(): first argument is not a string."))}function a(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 u(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 a(r);n[t]=e}return n}var c,f,h,s=(c=3432918353,f=461845907,h=3864292196,function(a){var s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;o(a,"murmurhash3_x86_32"),i(s);for(var g=u(a),v=g.length%4,l=g.length-v,d=0,w=0,y=s;w<l;)d=r(d=n(g,w),c),d=r(d=e(d,15),f),y=r(y=e(y^=d,13),5)+h,w+=4;switch(d=0,v){case 3:d^=(255&g[w+2])<<16;case 2:d^=(255&g[w+1])<<8;case 1:d=r(d^=g[w],c),y^=d=r(d=e(d,15),f)}return(y=t(y^=g.length))>>>0});module.exports=s;
//# sourceMappingURL=murmurhash3_x86_32.js.map