UNPKG

@stdlib/esm

Version:

ES module distribution for Stdlib, a standard library for JavaScript and Node.js.

3 lines 5 kB
// 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 a from"./../../assert/is-boolean.js";import o from"./../../assert/is-collection.js";import s from"./../../assert/is-positive-integer.js";import f from"./../../assert/is-int32array.js";import l from"./../../blas/base/gcopy.js";import m from"./../../math/base/special/floor.js";import u from"./../../array/int32.js";import p from"./../../constants/math/int32-max.js";import E from"./../../array/to-json.js";import h from"./../../math/base/assert/is-nan.js";var c=h,g=8;function d(e,t,n){var r,i;for(i=0;i<g;i++)if(r=e(),c(r))throw new Error("unexpected error. PRNG returned `NaN`.");for(i=n-1;i>=0;i--)t[i]=e();return t}var b=p,y=m,w=b-1;function v(){return 0|y(1+w*Math.random())}var N=e,T=t,M=n,j=r,R=i,_=a.isPrimitive,L=o,O=s.isPrimitive,A=f,P=l,x=m,S=u,B=p,Y=E,I=d,X=v,G=B-1|0,J=B-1|0,V=16807,k=32,z=1,q=3,C=2,D=k+3,F=k+6,H=k+7,K=D+1,Q=D+2;function U(e,t){var n;return n=t?"option":"argument",e.length<H+1?new RangeError("invalid "+n+". `state` array has insufficient length."):e[0]!==z?new RangeError("invalid "+n+". `state` array has an incompatible schema version. Expected: "+z+". Actual: "+e[0]+"."):e[1]!==q?new RangeError("invalid "+n+". `state` array has an incompatible number of sections. Expected: "+q+". Actual: "+e[1]+"."):e[C]!==k?new RangeError("invalid "+n+". `state` array has an incompatible table length. Expected: "+k+". Actual: "+e[C]+"."):2!==e[D]?new RangeError("invalid "+n+". `state` array has an incompatible state length. Expected: "+2..toString()+". Actual: "+e[D]+"."):e[F]!==e.length-H?new RangeError("invalid "+n+". `state` array length is incompatible with seed section length. Expected: "+(e.length-H)+". Actual: "+e[F]+"."):null}function W(e){var t,n,r,i,a,o;if(r={},arguments.length){if(!R(e))throw new TypeError("invalid argument. Options argument must be an object. Value: `"+e+"`.");if(j(e,"copy")&&(r.copy=e.copy,!_(e.copy)))throw new TypeError("invalid option. `copy` option must be a boolean. Option: `"+e.copy+"`.");if(j(e,"state")){if(n=e.state,r.state=!0,!A(n))throw new TypeError("invalid option. `state` option must be an Int32Array. Option: `"+n+"`.");if(o=U(n,!0))throw o;!1===r.copy?t=n:(t=new S(n.length),P(n.length,n,1,t,1)),n=new S(t.buffer,t.byteOffset+(C+1)*t.BYTES_PER_ELEMENT,k),i=new S(t.buffer,t.byteOffset+(F+1)*t.BYTES_PER_ELEMENT,n[F])}if(void 0===i)if(j(e,"seed"))if(i=e.seed,r.seed=!0,O(i)){if(i>J)throw new RangeError("invalid option. `seed` option must be a positive integer less than the maximum signed 32-bit integer. Option: `"+i+"`.");i|=0}else{if(!(L(i)&&i.length>0))throw new TypeError("invalid option. `seed` option must be either a positive integer less than the maximum signed 32-bit integer or an array-like object containing integer values less than the maximum signed 32-bit integer. Option: `"+i+"`.");a=i.length,(t=new S(H+a))[0]=z,t[1]=q,t[C]=k,t[D]=2,t[Q]=i[0],t[F]=a,P.ndarray(a,i,1,0,t,1,F+1),n=new S(t.buffer,t.byteOffset+(C+1)*t.BYTES_PER_ELEMENT,k),i=new S(t.buffer,t.byteOffset+(F+1)*t.BYTES_PER_ELEMENT,a),n=I(h,n,k),t[K]=n[0]}else i=0|X()}else i=0|X();return void 0===n&&((t=new S(H+1))[0]=z,t[1]=q,t[C]=k,t[D]=2,t[Q]=i,t[F]=1,t[F+1]=i,n=new S(t.buffer,t.byteOffset+(C+1)*t.BYTES_PER_ELEMENT,k),i=new S(t.buffer,t.byteOffset+(F+1)*t.BYTES_PER_ELEMENT,1),n=I(h,n,k),t[K]=n[0]),N(c,"NAME","minstd-shuffle"),T(c,"seed",s),T(c,"seedLength",f),M(c,"state",u,p),T(c,"stateLength",l),T(c,"byteLength",m),N(c,"toJSON",E),N(c,"MIN",1),N(c,"MAX",B-1),N(c,"normalized",g),N(g,"NAME",c.NAME),T(g,"seed",s),T(g,"seedLength",f),M(g,"state",u,p),T(g,"stateLength",l),T(g,"byteLength",m),N(g,"toJSON",E),N(g,"MIN",(c.MIN-1)/G),N(g,"MAX",(c.MAX-1)/G),c;function s(){var e=t[F];return P(e,i,1,new S(e),1)}function f(){return t[F]}function l(){return t.length}function m(){return t.byteLength}function u(){var e=t.length;return P(e,t,1,new S(e),1)}function p(e){var a;if(!A(e))throw new TypeError("invalid argument. Must provide an Int32Array. Value: `"+e+"`.");if(a=U(e,!1))throw a;!1===r.copy?r.state&&e.length===t.length?P(e.length,e,1,t,1):(t=e,r.state=!0):(e.length!==t.length&&(t=new S(e.length)),P(e.length,e,1,t,1)),n=new S(t.buffer,t.byteOffset+(C+1)*t.BYTES_PER_ELEMENT,k),i=new S(t.buffer,t.byteOffset+(F+1)*t.BYTES_PER_ELEMENT,t[F])}function E(){var e={type:"PRNG"};return e.name=c.NAME,e.state=Y(t),e.params=[],e}function h(){var e=0|t[Q];return e=V*e%B|0,t[Q]=e,0|e}function c(){var e,r;return e=t[K],r=x(k*(e/B)),e=n[r],t[K]=e,n[r]=h(),e}function g(){return(c()-1)/G}}var Z=W,$=v,ee=Z({seed:$()}),te=e,ne=ee,re=W;te(ne,"factory",re);export default ne; //# sourceMappingURL=minstd-shuffle.js.map