@stdlib/esm
Version:
ES module distribution for Stdlib, a standard library for JavaScript and Node.js.
3 lines • 3.99 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 r from"./../../utils/define-nonenumerable-read-only-accessor.js";import n from"./../../utils/define-nonenumerable-read-write-accessor.js";import t from"./../../assert/is-plain-object.js";import o from"./../../assert/is-function.js";import i from"./../../assert/has-own-property.js";import a from"./../../utils/constant-function.js";import s from"./../../utils/noop.js";import u from"./mt19937.js";import p from"./../../math/base/assert/is-nan.js";import m from"./../../math/base/assert/is-integer.js";import f from"./../../array/to-json.js";import l from"./../../assert/is-integer.js";import g from"./../../assert/is-nan.js";import d from"./../../constants/math/float64-max-safe-integer.js";import h from"./../../math/base/special/floor.js";var c=l.isPrimitive,v=g;function y(e,r){return!c(e)||v(e)?new TypeError("invalid argument. First argument must be an integer and not `NaN`. Value: `"+e+"`."):!c(r)||v(r)?new TypeError("invalid argument. Second argument must be an integer and not `NaN`. Value: `"+r+"`."):e>r?new RangeError("invalid argument. Minimum support `a` must be less than or equal to maximum support `b`. Value: `["+e+","+r+"]`."):null}var b=d,w=h;function j(e,r,n){var t,o,i,a,s,u,p,m;if(0===(i=n-r))return r;if(p=e.MIN,(o=e.MAX-p)===i)return e()-p+r;if(o<i)for(a=0;;){for(i===b?(a=w(i/(o+1)),i%(o+1)===o&&(a+=1)):a=w((i+1)/(o+1)),t=0,u=1;u<=a;){if(t+=(e()-p)*u,u*o==i-u+1)return t;u*=o+1}if(!((m=j(e,0,w(i/u)))>b/u||(t+=m*=u)>i))return t+r}for(o===b?(s=w(o/(i+1)),o%(i+1)===i&&(s+=1)):s=w((o+1)/(i+1));;)if(t=e()-p,(t=w(t/s))<=i)return t+r}var N=e,E=r,M=n,T=t,L=o,A=i,O=a,x=s,I=u.factory,V=p,X=m,P=f,R=y,G=j;function S(){var e,r,n,t,o,i;if(0===arguments.length)r=I();else if(1===arguments.length){if(!T(e=arguments[0]))throw new TypeError("invalid argument. Options argument must be an object. Value: `"+e+"`.");if(A(e,"prng")){if(!L(e.prng))throw new TypeError("invalid option. `prng` option must be a pseudorandom number generator function. Option: `"+e.prng+"`.");if(r=e.prng,!X(r.MIN))throw new TypeError("invalid option. `prng` option must have a `MIN` property specifying the minimum possible pseudorandom integer value.");if(!X(r.MAX))throw new TypeError("invalid option. `prng` option must have a `MAX` property specifying the maximum possible pseudorandom integer value.")}else r=I(e)}else{if(t=R(o=arguments[0],i=arguments[1]))throw t;if(arguments.length>2){if(!T(e=arguments[2]))throw new TypeError("invalid argument. Options argument must be an object. Value: `"+e+"`.");if(A(e,"prng")){if(!L(e.prng))throw new TypeError("invalid option. `prng` option must be a pseudorandom number generator function. Option: `"+e.prng+"`.");if(r=e.prng,!X(r.MIN))throw new TypeError("invalid option. `prng` option must have a `MIN` property specifying the minimum possible pseudorandom integer value.");if(!X(r.MAX))throw new TypeError("invalid option. `prng` option must have a `MAX` property specifying the maximum possible pseudorandom integer value.")}else r=I(e)}else r=I()}return N(n=void 0===o?d:g,"NAME","discrete-uniform"),e&&e.prng?(N(n,"seed",null),N(n,"seedLength",null),M(n,"state",O(null),x),N(n,"stateLength",null),N(n,"byteLength",null),N(n,"toJSON",O(null)),N(n,"PRNG",r)):(E(n,"seed",a),E(n,"seedLength",s),M(n,"state",m,f),E(n,"stateLength",u),E(n,"byteLength",p),N(n,"toJSON",l),N(n,"PRNG",r)),n;function a(){return r.seed}function s(){return r.seedLength}function u(){return r.stateLength}function p(){return r.byteLength}function m(){return r.state}function f(e){r.state=e}function l(){var e={type:"PRNG"};return e.name=n.NAME,e.state=P(r.state),e.params=void 0===o?[]:[o,i],e}function g(){return G(r,o,i)}function d(e,n){return V(e)||V(n)||!X(e)||!X(n)||e>n?NaN:G(r,e,n)}}var J=S,q=J(),F=e,k=q,z=S;F(k,"factory",z);export default k;
//# sourceMappingURL=discrete-uniform.js.map