random int between two numbers javascript
snippet in javascript

random int between two numbers javascript

user4690

// Between any two numbers
Math.floor(Math.random() * (max - min + 1)) + min;

// Between 0 and max
Math.floor(Math.random() * (max + 1));

// Between 1 and max
Math.floor(Math.random() * max) + 1;

javascript random no between 2 numbers

user5303

function randomIntFromInterval(min, max) { // min and max included 
  return Math.floor(Math.random() * (max - min + 1) + min);
}

javascript random number between

user5701

Math.floor(Math.random() * 6) + 1  

javascript random number between 1 and 3

user5517

Math.floor(Math.random() * 3);