UNPKG

@stdlib/esm

Version:

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

3 lines 3.51 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 r from"./../../utils/define-nonenumerable-read-write-accessor.js";import n from"./../../assert/is-function.js";import o from"./../../assert/is-plain-object.js";import i from"./../../assert/is-boolean.js";import s from"./../../assert/has-own-property.js";import a from"./../../assert/is-uint32array.js";import p from"./mt19937.js";import u from"./../../utils/constant-function.js";import m from"./../../utils/noop.js";import l from"./../../math/base/special/floor.js";import f from"./../../constants/math/uint32-max.js";import c from"./../../array/to-json.js";import d from"./../../math/base/special/abs.js";import h from"./../../math/base/special/exp.js";import y from"./../../math/base/special/sqrt.js";import g from"./../../math/base/special/ln.js";var b=y,v=h,j=g,w=.00991256303526217;function L(e,t){var r,n,o;for(r=new Array(e+1),n=v(-.5*t*t),r[0]=w/n,r[1]=t,r[e]=0,o=2;o<e;o++)r[o]=b(-2*j(w/r[o-1]+n)),n=v(-.5*r[o]*r[o]);return r}function E(e){var t,r;for(t=[],r=0;r<e.length-1;r++)t.push(e[r+1]/e[r]);return t}var N=g;function O(e,t,r){var n,o;do{n=N(e())/t,o=N(e())}while(-2*o<n*n);return r?n-t:t-n}var x=d,T=h,A=L,q=E,z=O,M=128,P=3.442619855899,G=A(M,P),J=q(G),R=127;function S(e,t){return function(){var r,n,o,i,s,a,p;for(;;){if(s=2*e()-1,a=t()&R,x(s)<J[a])return s*G[a];if(0===a)return z(e,P,s<0);if(i=s*G[a],o=i*i,p=a+1,r=T(-.5*(G[a]*G[a]-o)),(n=T(-.5*(G[p]*G[p]-o)))+e()*(r-n)<1)return i}}}var k=e,U=t,V=r,B=n,C=o,D=i.isPrimitive,F=s,H=a,I=p.factory,K=u,Q=m,W=l,X=f,Y=c,Z=S;function $(e){var t,r,n,o;if(o={copy:!0},arguments.length){if(!C(e))throw new TypeError("invalid argument. Must provide an object. Value: `"+e+"`.");if(F(e,"copy")&&(o.copy=e.copy,!D(e.copy)))throw new TypeError("invalid option. `copy` option must be a boolean. Option: `"+e.copy+"`.");if(F(e,"prng")){if(!B(e.prng))throw new TypeError("invalid option. `prng` option must be a pseudorandom number generator function. Option: `"+e.prng+"`.");t=e.prng}else if(F(e,"state")){if(o.state=e.state,!H(e.state))throw new TypeError("invalid option. `state` option must be a Uint32Array. Option: `"+e.state+"`.")}else if(F(e,"seed")&&(o.seed=e.seed,void 0===e.seed))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: `"+e.seed+"`.")}return void 0===o.state?void 0===t?t=(r=I(o)).normalized:(r=I({seed:W(1+X*t()),copy:o.copy}),o.seed=null):t=(r=I(o)).normalized,n=Z(t,r),k(n,"NAME","improved-ziggurat"),null===o.seed?(k(n,"seed",null),k(n,"seedLength",null)):(U(n,"seed",i),U(n,"seedLength",s)),e&&e.prng?(V(n,"state",K(null),Q),k(n,"stateLength",null),k(n,"byteLength",null),k(n,"toJSON",K(null))):(V(n,"state",u,m),U(n,"stateLength",a),U(n,"byteLength",p),k(n,"toJSON",l)),k(n,"PRNG",t),n;function i(){return r.seed}function s(){return r.seedLength}function a(){return r.stateLength}function p(){return r.byteLength}function u(){return r.state}function m(e){r.state=e}function l(){var e={type:"PRNG"};return e.name=n.NAME,e.state=Y(r.state),e.params=[],e}}var _=$,ee=_(),te=e,re=ee,ne=$;te(re,"factory",ne);export default re; //# sourceMappingURL=improved-ziggurat.js.map