Add _.random.

Former-commit-id: cf720b9187b0b54b43773a9f5f02fb475d786bfa
This commit is contained in:
John-David Dalton
2012-08-31 13:33:44 -07:00
parent 71639cfea7
commit a7e3136a0b
2 changed files with 65 additions and 5 deletions

View File

@@ -1161,6 +1161,27 @@
/*--------------------------------------------------------------------------*/
QUnit.module('lodash.random');
(function() {
test('should work like `Math.random` if no arguments are passed', function() {
var actual = _.random();
ok(actual >= 0 && actual < 1);
});
test('supports not passing a `max` argument', function() {
var actual = _.random(5),
start = new Date;
while ((new Date - start) < 50 && actual == 5) {
actual = _.random(5);
}
ok(actual != 5);
});
}());
/*--------------------------------------------------------------------------*/
QUnit.module('lodash.range');
(function() {