Underscore.JS - random method



Syntax

_.random(min, max)

random method returns a random number between min and max, both values inclusive. In case only one number is passed then random number is generated between 0 and given number. See the below example −

Example

var _ = require('underscore');

//Example 1: Get a random number between 3 and 10
console.log(_.random(3, 10));

//Example 2: Get a random number between 0 and 10
console.log(_.random(10));

Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

Output

9
5
underscorejs_utilities.htm
Advertisements