1 var baseRandom = require('../internal/baseRandom'),
2 isIterateeCall = require('../internal/isIterateeCall');
4 /* Native method references for those with the same name as other `lodash` methods. */
5 var nativeMin = Math.min,
6 nativeRandom = Math.random;
9 * Produces a random number between `min` and `max` (inclusive). If only one
10 * argument is provided a number between `0` and the given number is returned.
11 * If `floating` is `true`, or either `min` or `max` are floats, a floating-point
12 * number is returned instead of an integer.
17 * @param {number} [min=0] The minimum possible value.
18 * @param {number} [max=1] The maximum possible value.
19 * @param {boolean} [floating] Specify returning a floating-point number.
20 * @returns {number} Returns the random number.
24 * // => an integer between 0 and 5
27 * // => also an integer between 0 and 5
30 * // => a floating-point number between 0 and 5
33 * // => a floating-point number between 1.2 and 5.2
35 function random(min, max, floating) {
36 if (floating && isIterateeCall(min, max, floating)) {
37 max = floating = undefined;
39 var noMin = min == null,
42 if (floating == null) {
43 if (noMax && typeof min == 'boolean') {
47 else if (typeof max == 'boolean') {
63 if (floating || min % 1 || max % 1) {
64 var rand = nativeRandom();
65 return nativeMin(min + (rand * (max - min + parseFloat('1e-' + ((rand + '').length - 1)))), max);
67 return baseRandom(min, max);
70 module.exports = random;