- Underscore.JS Tutorial
- Underscore.JS - Home
- Underscore.JS - Overview
- Underscore.JS - Environment Setup
- Underscore.JS - Iterating Collection
- Underscore.JS - Processing Collection
- Underscore.JS - Iterating Array
- Underscore.JS - Processing Array
- Underscore.JS - Functions
- Underscore.JS - Mapping Objects
- Underscore.JS - Updating Objects
- Underscore.JS - Comparing Objects
- Underscore.JS - Utilities
- Underscore.JS - Chaining
- Underscore.JS Useful Resources
- Underscore.JS - Quick Guide
- Underscore.JS - Useful Resources
- Underscore.JS - Discussion
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