Generate a random integer - Node.js Number

Node.js examples for Number:Random Number

Description

Generate a random integer

Demo Code

/**/*from   ww  w . ja  v  a  2 s .  co m*/
 * Generate a random integer
 *
 * @param  {number} min Minimum boundary
 * @param  {number} max Maximum boundary
 * @return {number}     Generated integer
 */
export default function randomInt(min, max) {
  return Math.floor( Math.random() * ( max - min + 1 ) + min );
}

Related Tutorials