MCPcopy Create free account
hub / github.com/microsoft/SandDance / integer

Function integer

docs/app/js/sanddance-app.js:119237–119273  ·  view source on GitHub ↗
(min, max)

Source from the content-addressed store, hash-verified

119235 };
119236}
119237function integer(min, max) {
119238 if (max == null) {
119239 max = min;
119240 min = 0;
119241 }
119242 let a, b, d;
119243 const dist = {
119244 min (_) {
119245 if (arguments.length) {
119246 a = _ || 0;
119247 d = b - a;
119248 return dist;
119249 } else return a;
119250 },
119251 max (_) {
119252 if (arguments.length) {
119253 b = _ || 0;
119254 d = b - a;
119255 return dist;
119256 } else return b;
119257 },
119258 sample () {
119259 return a + Math.floor(d * random());
119260 },
119261 pdf (x) {
119262 return x === Math.floor(x) && x >= a && x < b ? 1 / d : 0;
119263 },
119264 cdf (x) {
119265 const v = Math.floor(x);
119266 return v < a ? 0 : v >= b ? 1 : (v - a + 1) / d;
119267 },
119268 icdf (p) {
119269 return p >= 0 && p <= 1 ? a - 1 + Math.floor(p * d) : NaN;
119270 }
119271 };
119272 return dist.min(min).max(max);
119273}
119274const SQRT2PI = Math.sqrt(2 * Math.PI);
119275const SQRT2 = Math.SQRT2;
119276let nextSample = NaN;

Callers

nothing calls this directly

Calls 2

maxMethod · 0.45
minMethod · 0.45

Tested by

no test coverage detected