@stdlib/esm
Version:
ES module distribution for Stdlib, a standard library for JavaScript and Node.js.
3 lines • 4.36 kB
JavaScript
// This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0
import t from"./../../utils/define-nonenumerable-read-only-property.js";import e from"./../../utils/define-nonenumerable-read-only-accessor.js";import r from"./../../utils/define-nonenumerable-read-write-accessor.js";import n from"./../../assert/is-plain-object.js";import o from"./../../assert/is-uint32array.js";import i from"./../../assert/is-boolean.js";import a from"./../../assert/is-function.js";import s from"./../../assert/has-own-property.js";import p from"./../../utils/constant-function.js";import m from"./../../utils/noop.js";import u from"./improved-ziggurat.js";import l from"./mt19937.js";import f from"./../../math/base/assert/is-nan.js";import c from"./../../math/base/special/sqrt.js";import g from"./../../math/base/special/pow.js";import y from"./../../blas/base/gcopy.js";import h from"./../../array/uint32.js";import b from"./../../array/to-json.js";import d from"./../../utils/copy.js";import v from"./../../assert/is-positive-number.js";import w from"./../../math/base/special/ln.js";var j=v.isPrimitive;function E(t,e){return j(t)?j(e)?null:new TypeError("invalid argument. `beta` must be a positive number. Value: `"+e+"`."):new TypeError("invalid argument. `alpha` must be a positive number. Value: `"+t+"`.")}var T=w;function O(t,e,r,n,o){var i,a,s,p,m,u,l;for(i=!0;i;){do{l=1+o*(m=e())}while(l<=0);s=1-.331*(a=m*m)*a,p=.5*a+n*(1-(l*=l*l)+T(l)),((u=t())<s||T(u)<p)&&(i=!1)}return 1/r*n*l}var L=t,N=e,A=r,P=n,V=o,G=i.isPrimitive,M=a,R=s,U=p,z=m,J=u.factory,S=l.factory,q=f,x=c,k=g,B=y,C=h,D=b,F=d,H=E,I=O,K=1/3;function Q(){var t,e,r,n,o,i,a,s,p,m,u;if(s=!0,0===arguments.length)i=S(o={copy:!1});else if(1===arguments.length){if(!P(o=arguments[0]))throw new TypeError("invalid argument. Options argument must be an object. Value: `"+o+"`.");if(R(o,"copy")&&!G(o.copy))throw new TypeError("invalid option. `copy` option must be a boolean. Option: `"+o.copy+"`.");if(R(o,"prng")){if(!M(o.prng))throw new TypeError("invalid option. `prng` option must be a pseudorandom number generator function. Option: `"+o.prng+"`.");i=o.prng}else{if(R(o,"state")&&!V(o.state))throw new TypeError("invalid option. `state` option must be a Uint32Array. Option: `"+o.state+"`.");!1===(o=F(o,1)).copy?s=!1:o.state&&(o.state=B(o.state.length,o.state,1,new C(o.state.length),1)),o.copy=!1,i=S(o)}}else{if(p=H(e=arguments[0],n=arguments[1]))throw p;if(arguments.length>2){if(!P(o=arguments[2]))throw new TypeError("invalid argument. Options argument must be an object. Value: `"+o+"`.");if(R(o,"copy")&&!G(o.copy))throw new TypeError("invalid option. `copy` option must be a boolean. Option: `"+o.copy+"`.");if(R(o,"prng")){if(!M(o.prng))throw new TypeError("invalid option. `prng` option must be a pseudorandom number generator function. Option: `"+o.prng+"`.");i=o.prng}else{if(R(o,"state")&&!V(o.state))throw new TypeError("invalid option. `state` option must be a Uint32Array. Option: `"+o.state+"`.");!1===(o=F(o,1)).copy?s=!1:o.state&&(o.state=B(o.state.length,o.state,1,new C(o.state.length),1)),o.copy=!1,i=S(o)}}else i=S(o={copy:!1})}return o&&o.prng?r=J({prng:o.prng}):(o.state?t=o.state:(t=i.state,i.state=t),r=J({state:t,copy:!1})),void 0===e?a=w:(e>=1?(a=d,u=e-K):(a=v,u=e+1-K),m=1/x(9*u)),L(a,"NAME","gamma"),o&&o.prng?(L(a,"seed",null),L(a,"seedLength",null),A(a,"state",U(null),z),L(a,"stateLength",null),L(a,"byteLength",null),L(a,"toJSON",U(null)),L(a,"PRNG",i)):(N(a,"seed",l),N(a,"seedLength",f),A(a,"state",y,h),N(a,"stateLength",c),N(a,"byteLength",g),L(a,"toJSON",b),L(a,"PRNG",i),i=i.normalized),a;function l(){return i.seed}function f(){return i.seedLength}function c(){return i.stateLength}function g(){return i.byteLength}function y(){return i.state}function h(t){if(!V(t))throw new TypeError("invalid argument. Must provide a Uint32Array. Value: `"+t+"`.");s&&(t=B(t.length,t,1,new C(t.length),1)),i.state=t}function b(){var t={type:"PRNG"};return t.name=a.NAME,t.state=D(i.state),t.params=void 0===e?[]:[e,n],t}function d(){return I(i,r,n,u,m)}function v(){return I(i,r,n,u,m)*k(i(),1/e)}function w(t,e){var n,o;return q(t)||q(e)||t<=0||e<=0?NaN:t<1?(n=1/x(9*(o=t+1-K)),I(i,r,e,o,n)*k(i(),1/t)):(n=1/x(9*(o=t-K)),I(i,r,e,o,n))}}var W=Q,X=W(),Y=t,Z=X,$=Q;Y(Z,"factory",$);export default Z;
//# sourceMappingURL=gamma.js.map