Javascript Math random() get random number between two values

Introduction

To get a random number between two values

The returned value is no lower than (possibly equal) min, and is less than (and not equal) max.

function getRandom(min, max) {
  return Math.random() * (max - min) + min;
}
console.log(getRandom(1, 10));//w w  w  .  j a va 2  s.  co  m
console.log(getRandom(1, 10));
console.log(getRandom(1, 10));
console.log(getRandom(1, 10));
console.log(getRandom(1, 10));



PreviousNext

Related