MCPcopy Index your code
hub / github.com/stemkoski/stemkoski.github.com / random

Function random

MathBox/mathbox-bundle.js:41203–41232  ·  view source on GitHub ↗

* Produces a random number between `min` and `max` (inclusive). If only one * argument is provided a number between `0` and the given number will be * returned. If `floating` is truey or either `min` or `max` are floats a * floating-point number will be returned instead of an integer.

(min, max, floating)

Source from the content-addressed store, hash-verified

41201 * // => a floating-point number between 1.2 and 5.2
41202 */
41203 function random(min, max, floating) {
41204 var noMin = min == null,
41205 noMax = max == null;
41206
41207 if (floating == null) {
41208 if (typeof min == 'boolean' && noMax) {
41209 floating = min;
41210 min = 1;
41211 }
41212 else if (!noMax && typeof max == 'boolean') {
41213 floating = max;
41214 noMax = true;
41215 }
41216 }
41217 if (noMin && noMax) {
41218 max = 1;
41219 }
41220 min = +min || 0;
41221 if (noMax) {
41222 max = min;
41223 min = 0;
41224 } else {
41225 max = +max || 0;
41226 }
41227 if (floating || min % 1 || max % 1) {
41228 var rand = nativeRandom();
41229 return nativeMin(min + (rand * (max - min + parseFloat('1e-' + ((rand +'').length - 1)))), max);
41230 }
41231 return baseRandom(min, max);
41232 }
41233
41234 /**
41235 * Resolves the value of property `key` on `object`. If `key` is a function

Callers

nothing calls this directly

Calls 1

baseRandomFunction · 0.85

Tested by

no test coverage detected