get random whole number javascript code example

Example 1: javascript random

function random(min, max) {
  return ~~(Math.random() * (max - min + 1) + min);
}
random(1, 5);

Example 2: Generate random whole numbers javascript

var randomWholeNumber = Math.floor(Math.random() * 20);


function randomWholeNum() {

	return Math.floor(Math.random() * 10);

}

console.log(randomWholeNum());

Example 3: randint js

/* If 1 argument is given, minimum will be set to 0 and maximum to this argument
 * If 2 arguments were given, the fist would be the minimum and the second the maximum
 * The function will return an integer in [min, max[
 */
const Math.randint => (min,max) {
  [min,max] = (max===undefined)?[0,min]:(min>max)[max,min]:[min,max];
  return Math.floor(Math.random*(max-min)+min);
}

Example 4: math.floor + roandom

//Write the following code to get a random number between 1 and 10
       const result = Math.floor(Math.random()*(10)+ 1);