Q:

math.random

// 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;
12
//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 getRandomInt(min, max) {
  return Math.floor(Math.random() * (max - min)) + min;
}
2
function getRandomNumberBetween(min,max){
    return Math.floor(Math.random()*(max-min+1)+min);
}

//usage example: getRandomNumberBetween(20,400); 
25
Math.floor((Math.random() * 100) + 1);
//Generate random numbers between 1 and 100
//Math.random generates [0,1)
10
function randomNumber(min, max) {
  return Math.floor(Math.random() * (max - min)) + min;
}
11
function getRandomIntInclusive(min, max) {
  min = Math.ceil(min);
  max = Math.floor(max);
  return Math.floor(Math.random() * (max - min + 1)) + min; //The maximum is inclusive and the minimum is inclusive 
}
4
function getRandomNumberBetween(min,max){
    return Math.floor(Math.random()*(max-min+1)+min);
}
4
Math.floor(Math.random() * 10);
11
function randomInteger(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}
4
<script>
function randomNum(min,max){
var number = Math.random(min,max)
document.getElementById("text").innerHTML = number;
};
</script>
<button onclick="randomNum(0,10)"></button>
<p id=text></p>
<!-- must add </p>, or <div id=text ></div>, this code will set 
 <p id=text></p> to a random number through 0-10 ex: 7-->
-1

Tags

Related

New to Communities?

Join the community