Get random from within a range - Node.js Number

Node.js examples for Number:Random Number

Description

Get random from within a range

Demo Code


function getRandom ( min, max )
{
  var res = Math.random();
    // uniform random distributed in [0, 1)
  
  res = min + (max - min)*res;/*from w ww. java  2s  .  c o m*/
  
  return res;
}

Related Tutorials