@stdlib/esm
Version:
ES module distribution for Stdlib, a standard library for JavaScript and Node.js.
3 lines • 6.42 kB
JavaScript
// This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0
import e from"./../../utils/define-nonenumerable-read-only-property.js";import t from"./../../utils/define-nonenumerable-read-only-accessor.js";import n from"./../../utils/define-nonenumerable-read-write-accessor.js";import r from"./../../assert/has-own-property.js";import i from"./../../assert/is-plain-object.js";import o from"./../../assert/is-collection.js";import a from"./../../assert/is-uint32array.js";import s from"./../../assert/is-boolean.js";import l from"./../../assert/is-positive-integer.js";import f from"./../../constants/math/float64-max-safe-integer.js";import u from"./../../constants/math/uint32-max.js";import m from"./../../array/uint32.js";import p from"./../../math/base/special/max.js";import h from"./../../math/base/special/uimul.js";import g from"./../../blas/base/gcopy.js";import c from"./../../array/to-json.js";import E from"./../../math/base/special/floor.js";var b=u,d=E,y=b-1;function v(){return d(1+y*Math.random())>>>0}var w=e,j=t,T=n,M=r,N=i,O=o,R=a,x=s.isPrimitive,_=l.isPrimitive,L=f,A=u,P=m,S=p,B=h,Y=g,q=c,k=v,I=624,J=397,U=A>>>0,V=19650218,X=2147483648,z=2147483647,G=1812433253,C=1664525,D=1566083941,F=2636928640,H=4022730752,K=2567483615,Q=[0,K>>>0],W=1/(f+1),Z=67108864,$=2147483648,ee=1,te=f*W,ne=1,re=3,ie=2,oe=I+3,ae=I+5,se=I+6;function le(e,t){var n;return n=t?"option":"argument",e.length<se+1?new RangeError("invalid "+n+". `state` array has insufficient length."):e[0]!==ne?new RangeError("invalid "+n+". `state` array has an incompatible schema version. Expected: "+ne+". Actual: "+e[0]+"."):e[1]!==re?new RangeError("invalid "+n+". `state` array has an incompatible number of sections. Expected: "+re+". Actual: "+e[1]+"."):e[ie]!==I?new RangeError("invalid "+n+". `state` array has an incompatible state length. Expected: "+I+". Actual: "+e[ie]+"."):1!==e[oe]?new RangeError("invalid "+n+". `state` array has an incompatible section length. Expected: "+1..toString()+". Actual: "+e[oe]+"."):e[ae]!==e.length-se?new RangeError("invalid "+n+". `state` array length is incompatible with seed section length. Expected: "+(e.length-se)+". Actual: "+e[ae]+"."):null}function fe(e,t,n){var r;for(e[0]=n>>>0,r=1;r<t;r++)n=((n=e[r-1]>>>0)^n>>>30)>>>0,e[r]=B(n,G)+r>>>0;return e}function ue(e,t,n,r){var i,o,a,s;for(o=1,a=0,s=S(t,r);s>0;s--)i=e[o-1]>>>0,i=B(i=(i^i>>>30)>>>0,C)>>>0,e[o]=(e[o]>>>0^i)+n[a]+a>>>0,a+=1,(o+=1)>=t&&(e[0]=e[t-1],o=1),a>=r&&(a=0);for(s=t-1;s>0;s--)i=e[o-1]>>>0,i=B(i=(i^i>>>30)>>>0,D)>>>0,e[o]=(e[o]>>>0^i)-o>>>0,(o+=1)>=t&&(e[0]=e[t-1],o=1);return e[0]=$,e}function me(e){var t,n,r,i;for(i=I-J,n=0;n<i;n++)t=e[n]&X|e[n+1]&z,e[n]=e[n+J]^t>>>1^Q[t&ee];for(r=I-1;n<r;n++)t=e[n]&X|e[n+1]&z,e[n]=e[n-i]^t>>>1^Q[t&ee];return t=e[r]&X|e[0]&z,e[r]=e[J-1]^t>>>1^Q[t&ee],e}function pe(e){var t,n,r,i,o,a;if(r={},arguments.length){if(!N(e))throw new TypeError("invalid argument. Options argument must be an object. Value: `"+e+"`.");if(M(e,"copy")&&(r.copy=e.copy,!x(e.copy)))throw new TypeError("invalid option. `copy` option must be a boolean. Option: `"+e.copy+"`.");if(M(e,"state")){if(n=e.state,r.state=!0,!R(n))throw new TypeError("invalid option. `state` option must be a Uint32Array. Option: `"+n+"`.");if(a=le(n,!0))throw a;!1===r.copy?t=n:(t=new P(n.length),Y(n.length,n,1,t,1)),n=new P(t.buffer,t.byteOffset+(ie+1)*t.BYTES_PER_ELEMENT,I),i=new P(t.buffer,t.byteOffset+(ae+1)*t.BYTES_PER_ELEMENT,n[ae])}if(void 0===i)if(M(e,"seed"))if(i=e.seed,r.seed=!0,_(i)){if(i>U)throw new RangeError("invalid option. `seed` option must be a positive integer less than or equal to the maximum unsigned 32-bit integer. Option: `"+i+"`.");i>>>=0}else{if(!1===O(i)||i.length<1)throw new TypeError("invalid option. `seed` option must be either a positive integer less than or equal to the maximum unsigned 32-bit integer or an array-like object containing integer values less than or equal to the maximum unsigned 32-bit integer. Option: `"+i+"`.");if(1===i.length){if(i=i[0],!_(i))throw new TypeError("invalid option. `seed` option must be either a positive integer less than or equal to the maximum unsigned 32-bit integer or an array-like object containing integer values less than or equal to the maximum unsigned 32-bit integer. Option: `"+i+"`.");if(i>U)throw new RangeError("invalid option. `seed` option must be either a positive integer less than or equal to the maximum unsigned 32-bit integer or an array-like object containing integer values less than or equal to the maximum unsigned 32-bit integer. Option: `"+i+"`.");i>>>=0}else o=i.length,(t=new P(se+o))[0]=ne,t[1]=re,t[ie]=I,t[oe]=1,t[oe+1]=I,t[ae]=o,Y.ndarray(o,i,1,0,t,1,ae+1),n=new P(t.buffer,t.byteOffset+(ie+1)*t.BYTES_PER_ELEMENT,I),i=new P(t.buffer,t.byteOffset+(ae+1)*t.BYTES_PER_ELEMENT,o),n=ue(n=fe(n,I,V),I,i,o)}else i=k()>>>0}else i=k()>>>0;return void 0===n&&((t=new P(se+1))[0]=ne,t[1]=re,t[ie]=I,t[oe]=1,t[oe+1]=I,t[ae]=1,t[ae+1]=i,n=new P(t.buffer,t.byteOffset+(ie+1)*t.BYTES_PER_ELEMENT,I),i=new P(t.buffer,t.byteOffset+(ae+1)*t.BYTES_PER_ELEMENT,1),n=fe(n,I,i)),w(g,"NAME","mt19937"),j(g,"seed",s),j(g,"seedLength",l),T(g,"state",m,p),j(g,"stateLength",f),j(g,"byteLength",u),w(g,"toJSON",h),w(g,"MIN",1),w(g,"MAX",A),w(g,"normalized",c),w(c,"NAME",g.NAME),j(c,"seed",s),j(c,"seedLength",l),T(c,"state",m,p),j(c,"stateLength",f),j(c,"byteLength",u),w(c,"toJSON",h),w(c,"MIN",0),w(c,"MAX",te),g;function s(){var e=t[ae];return Y(e,i,1,new P(e),1)}function l(){return t[ae]}function f(){return t.length}function u(){return t.byteLength}function m(){var e=t.length;return Y(e,t,1,new P(e),1)}function p(e){var o;if(!R(e))throw new TypeError("invalid argument. Must provide a Uint32Array. Value: `"+e+"`.");if(o=le(e,!1))throw o;!1===r.copy?r.state&&e.length===t.length?Y(e.length,e,1,t,1):(t=e,r.state=!0):(e.length!==t.length&&(t=new P(e.length)),Y(e.length,e,1,t,1)),n=new P(t.buffer,t.byteOffset+(ie+1)*t.BYTES_PER_ELEMENT,I),i=new P(t.buffer,t.byteOffset+(ae+1)*t.BYTES_PER_ELEMENT,t[ae])}function h(){var e={type:"PRNG"};return e.name=g.NAME,e.state=q(t),e.params=[],e}function g(){var e,r;return(r=t[oe+1])>=I&&(n=me(n),r=0),e=n[r],t[oe+1]=r+1,e^=e>>>11,e^=e<<7&F,e^=e<<15&H,(e^=e>>>18)>>>0}function c(){var e=g()>>>5,t=g()>>>6;return(e*Z+t)*W}}var he=pe,ge=v,ce=he({seed:ge()}),Ee=e,be=ce,de=pe;Ee(be,"factory",de);export default be;
//# sourceMappingURL=mt19937.js.map