@stdlib/esm
Version:
ES module distribution for Stdlib, a standard library for JavaScript and Node.js.
3 lines • 3.96 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"./../assert/is-array-like.js";import t from"./../assert/is-string.js";import i from"./base/mt19937.js";import o from"./../utils/copy.js";import n from"./../math/base/special/floor.js";import a from"./../assert/is-nonnegative-integer.js";import s from"./../assert/is-unity-probability-array.js";import p from"./../assert/has-own-property.js";import l from"./../assert/is-boolean.js";import u from"./../assert/is-plain-object.js";var m=n;function f(e,r,t){var i,o,n,a;for(n=e.length,o=new Array(r),a=0;a<r;a++)i=m(n*t()),o[a]=e[i];return o}function h(e,r,t,i){var o,n,a,s,p,l,u,m;for(s=e.length,o=new Array(s),p=0;p<s;p++)o[p]=i[p];for(a=new Array(r),p=0;p<r;p++){for(m=t(),n=0,l=0;l<s&&!(m<(n+=o[l]));l++);for(u=0;u<s;u++)u!==l&&(o[u]/=1-o[l]);o[l]=0,a[p]=e[l]}return a}var c=n,v=Array.prototype.slice;function g(e,r,t){var i,o,n;for(o=e.length-1;o>0;o--)n=c(t()*(o+1)),i=e[o],e[o]=e[n],e[n]=i;return v.call(e,0,r)}var y=n;function b(e,r,t,i){var o,n,a,s,p,l,u,m,f,h;for(a=i.slice(),l=e.length,o=[],n=[],f=0;f<l;f++)a[f]*=l,a[f]<1?o.push(f):n.push(f);for(s=new Array(l),u=new Array(l);0!==o.length&&0!==n.length;)h=o.shift(),m=n.shift(),u[h]=a[h],s[h]=m,a[m]=a[m]+a[h]-1,a[m]<1?o.push(m):n.push(m);for(f=0;f<n.length;f++)u[n[f]]=1;for(f=0;f<o.length;f++)u[o[f]]=1;for(p=new Array(r),f=0;f<r;f++)h=y(l*t()),t()<u[h]?p[f]=e[h]:p[f]=e[s[h]];return p}var w=!1,d=!0,z={mutate:w,replace:d},j=a,E=s,A=p,O=l.isPrimitive,T=u;function k(e,r){return T(r)?A(r,"size")&&(e.size=r.size,!j(e.size))?new TypeError("invalid option. `size` option must be a nonnegative integer. Option: `"+e.size+"`."):A(r,"probs")&&(e.probs=r.probs,!E(e.probs))?new TypeError("invalid option. `probs` option must be an array of probabilities that sum to one. Option: `"+e.probs+"`."):A(r,"mutate")&&(e.mutate=r.mutate,!O(e.mutate))?new TypeError("invalid option. `mutate` option must be a boolean primitive. Option: `"+e.mutate+"`."):A(r,"replace")&&(e.replace=r.replace,!O(e.replace))?new TypeError("invalid option. `replace` option must be a boolean primitive. Option: `"+e.replace+"`."):null:new TypeError("invalid argument. Options argument must be an object. Value: `"+r+"`.")}var P=e,R=r,V=t.isPrimitive,q=i.factory,x=o,F=f,G=h,N=g,B=b,C=z,D=k,H=Array.prototype.slice;function I(){var e,r,t,i,o,n;if(t=x(C),1===arguments.length)R(arguments[0])?r=arguments[0]:o=D(t,e=arguments[0]);else if(arguments.length>1){if(e=arguments[1],!R(r=arguments[0]))throw new TypeError("invalid argument. `pool` argument must be array-like. Value: `"+r+"`.");o=D(t,e)}if(o)throw o;return i=e&&e.seed?q({seed:e.seed}):q(),void 0===r?n=a:(r=V(r)?r.split(""):x(r),n=s),P(n,"seed",i.seed),P(n,"PRNG",i),i=i.normalized,n;function a(e,r){var o,n,a,s,p,l;if(!R(e))throw new TypeError("invalid argument. First argument must be array-like. Value: `"+e+"`.");if(V(e)&&(e=e.split("")),s={},arguments.length>1&&(l=D(s,r)))throw l;if(o=void 0===s.replace?t.replace:s.replace,void 0!==s.probs&&(a=s.probs),p=s.size?s.size:t.size?t.size:e.length,!1===o&&p>e.length)throw new RangeError("invalid input option. `size` option must be less than or equal to the length of `x` when `replace` is `false`. Option: `"+p+"`.");return a?o?B(e,p,i,a):G(e,p,i,a):o?F(e,p,i):(n=H.call(e),N(n,p,i))}function s(e){var o,n,a,s,p,l;if(0===r.length)return null;if(a={},arguments.length&&(p=D(a,e)))throw p;if(n=void 0===a.mutate?t.mutate:a.mutate,o=void 0===a.replace?t.replace:a.replace,s=a.size?a.size:t.size?t.size:r.length,!1===o&&s>r.length)throw new RangeError("invalid input option. `size` option must be less than or equal to the population size when `replace` is `false`. Option: `"+s+"`.");return o?F(r,s,i):(l=N(r,s,i),n&&(r=r.slice(s,r.length)),l)}}var J=I,K=J(),L=e,M=K,Q=I;L(M,"factory",Q);export default M;
//# sourceMappingURL=sample.js.map