LjL
0
Q:

js random int

Math.floor(Math.random() * 6) + 1  
14
var random;
var max = 8
function findRandom() {
  random = Math.floor(Math.random() * max) //Finds number between 0 - max
  console.log(random)
}
findRandom()
7
Math.floor((Math.random() * 100) + 1);
//Generate random numbers between 1 and 100
//Math.random generates [0,1)
10
//Returns a number between 1 and 0
  console.log(Math.random());
  
//if you want a random number between two particular numbers, 
//you can use this function
  function getRandomBetween(min, max) {
    return Math.random() * (max - min) + min;
  }
//Returns a random number between 20 and 170
  console.log(getRandomBetween(20,170));
  
//if you want a random integer number from one number to another 
//(including the min and the max numbers), you can use this function
  function getRandomIntBetween(min, max) {
    min = Math.ceil(min);
    max = Math.floor(max);
    return Math.floor(Math.random() * (max - min + 1)) + min;
  }
  
//Returns a random integer number from 0 to 25
  console.log(getRandomIntInclusive(0,25));
6
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;
0
Math.floor(Math.random() * 10);
11

function getRndInteger(min, max) {

    return Math.floor(Math.random() * (max - min + 1) ) + min;

}
 
1
function randomInteger(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}
4
Math.floor(Math.random() * 10) + 1
3
/**
* Gets random int
* @param min 
* @param max 
* @returns random int - min & max inclusive
*/
getRandomInt(min, max) : number{
	min = Math.ceil(min);
	max = Math.floor(max);
	return Math.floor(Math.random() * (max - min + 1)) + min; 
}
1
let int = Math.floor(Math.random() * 10);
1
//Returns random Int between 0 and 2 (included)
Math.floor(Math.random()*3)
1
function getRandomInt(min, max) {
    min = Math.ceil(min);
    max = Math.floor(max);
    return Math.floor(Math.random() * (max - min + 1)) + min;
}
1

New to Communities?

Join the community