diff --git a/doc/README.md b/doc/README.md index 398ba38f8..39838da46 100644 --- a/doc/README.md +++ b/doc/README.md @@ -2852,10 +2852,10 @@ Produces a random number between `min` and `max` *(inclusive)*. If only one argu #### Example ```js _.random(0, 5); -// => a number between 1 and 5 +// => a number between 0 and 5 _.random(5); -// => also a number between 1 and 5 +// => also a number between 0 and 5 ``` * * * diff --git a/lodash.js b/lodash.js index 405fb93b6..a79941cd9 100644 --- a/lodash.js +++ b/lodash.js @@ -3889,10 +3889,10 @@ * @example * * _.random(0, 5); - * // => a number between 1 and 5 + * // => a number between 0 and 5 * * _.random(5); - * // => also a number between 1 and 5 + * // => also a number between 0 and 5 */ function random(min, max) { if (min == null && max == null) { diff --git a/test/test.js b/test/test.js index 06972c0af..8bc19960c 100644 --- a/test/test.js +++ b/test/test.js @@ -1396,6 +1396,24 @@ } notEqual(actual, 5); }); + + test('supports large integer values', function() { + var array = Array(1000), + min = Math.pow(2, 31), + max = Math.pow(2, 62); + + ok(_.every(array, function() { + return _.random(min, max) >= min; + })); + + ok(_.some(array, function() { + return _.random(Number.MAX_VALUE) > 0; + })); + }); + + test('should coerce arguments to numbers', function() { + strictEqual(_.random('1', '1'), 1); + }); }()); /*--------------------------------------------------------------------------*/