Q:

javascript random number between 1 and 10

//To genereate a number between 0-1
Math.random();
//To generate a number that is a whole number rounded down
Math.floor(Math.random())
/*To generate a number that is a whole number rounded down between
1 and 10 */
Math.floor(Math.random() * 10) + 1 //the + 1 makes it so its not 0.
25
function randomNumber(min, max) {
  return Math.floor(Math.random() * (max - min)) + min + 1;
}
5
Math.floor(Math.random() * 6) + 1  
14
function getRandomNumberBetween(min,max){
    return Math.floor(Math.random()*(max-min+1)+min);
}

//usage example: getRandomNumberBetween(20,400); 
25
function randomNumber(min, max) {
  return Math.floor(Math.random() * (max - min)) + min;
}
11
var RandomNumber = Math.ceil(Math.random() * 100);              
// Returns a random number between 1 and 100
5
// Genereates a number between 0 to 1;
Math.random();

// to gerate a randome rounded number between 1 to 10;
var theRandomNumber = Math.floor(Math.random() * 10) + 1;
1
Math.floor(Math.random() * 10);
11
function randomInteger(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}
4
function randomNumber(min, max) {
  return Math.random() * (max - min) + min;
}
4
Math.floor(Math.random() * 10) + 1
3
//Returns random Int between 0 and 2 (included)
Math.floor(Math.random()*3)
1
Math.floor(Math.random() * 3);
5

New to Communities?

Join the community