MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / random

Function random

lib/web/jshint.js:11526–11559  ·  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 is returned. * If `floating` is `true`, or either `min` or `max` are floats, a floating-point * number is returned instead of an integer. *

(min, max, floating)

Source from the content-addressed store, hash-verified

11524 * // => a floating-point number between 1.2 and 5.2
11525 */
11526 function random(min, max, floating) {
11527 if (floating && isIterateeCall(min, max, floating)) {
11528 max = floating = null;
11529 }
11530 var noMin = min == null,
11531 noMax = max == null;
11532
11533 if (floating == null) {
11534 if (noMax && typeof min == 'boolean') {
11535 floating = min;
11536 min = 1;
11537 }
11538 else if (typeof max == 'boolean') {
11539 floating = max;
11540 noMax = true;
11541 }
11542 }
11543 if (noMin && noMax) {
11544 max = 1;
11545 noMax = false;
11546 }
11547 min = +min || 0;
11548 if (noMax) {
11549 max = min;
11550 min = 0;
11551 } else {
11552 max = +max || 0;
11553 }
11554 if (floating || min % 1 || max % 1) {
11555 var rand = nativeRandom();
11556 return nativeMin(min + (rand * (max - min + parseFloat('1e-' + ((rand + '').length - 1)))), max);
11557 }
11558 return baseRandom(min, max);
11559 }
11560
11561 /*------------------------------------------------------------------------*/
11562

Callers 1

uidFunction · 0.85

Calls 2

isIterateeCallFunction · 0.85
baseRandomFunction · 0.85

Tested by

no test coverage detected