js random integer between code example

Example 1: javascript random no between 2 numbers

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

Example 2: javascript get random number in range

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

//usage example: getRandomNumberBetween(20,400);

Example 3: generate random number javascript

function randomNumber(min, max) {
  return Math.floor(Math.random() * (max - min)) + min;
}

Example 4: javascript random number between

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

Example 5: js random generator

var options = ["Your options", "Another option!", "This is an option."];
var chosenOption = Math.floor(Math.random() * options.length);
console.log(options[option]);

Tags:

Dart Example