react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / js-yaml / node_modules / argparse / node_modules / lodash / number / random.js
80742 viewsvar baseRandom = require('../internal/baseRandom'),1isIterateeCall = require('../internal/isIterateeCall');23/* Native method references for those with the same name as other `lodash` methods. */4var nativeMin = Math.min,5nativeRandom = Math.random;67/**8* Produces a random number between `min` and `max` (inclusive). If only one9* argument is provided a number between `0` and the given number is returned.10* If `floating` is `true`, or either `min` or `max` are floats, a floating-point11* number is returned instead of an integer.12*13* @static14* @memberOf _15* @category Number16* @param {number} [min=0] The minimum possible value.17* @param {number} [max=1] The maximum possible value.18* @param {boolean} [floating] Specify returning a floating-point number.19* @returns {number} Returns the random number.20* @example21*22* _.random(0, 5);23* // => an integer between 0 and 524*25* _.random(5);26* // => also an integer between 0 and 527*28* _.random(5, true);29* // => a floating-point number between 0 and 530*31* _.random(1.2, 5.2);32* // => a floating-point number between 1.2 and 5.233*/34function random(min, max, floating) {35if (floating && isIterateeCall(min, max, floating)) {36max = floating = null;37}38var noMin = min == null,39noMax = max == null;4041if (floating == null) {42if (noMax && typeof min == 'boolean') {43floating = min;44min = 1;45}46else if (typeof max == 'boolean') {47floating = max;48noMax = true;49}50}51if (noMin && noMax) {52max = 1;53noMax = false;54}55min = +min || 0;56if (noMax) {57max = min;58min = 0;59} else {60max = +max || 0;61}62if (floating || min % 1 || max % 1) {63var rand = nativeRandom();64return nativeMin(min + (rand * (max - min + parseFloat('1e-' + ((rand + '').length - 1)))), max);65}66return baseRandom(min, max);67}6869module.exports = random;707172