javascript get random number in range
function getRandomNumberBetween(min,max){
return Math.floor(Math.random()*(max-min+1)+min);
}
//usage example: getRandomNumberBetween(20,400);
javascript get random number in range
function getRandomNumberBetween(min,max){
return Math.floor(Math.random()*(max-min+1)+min);
}
//usage example: getRandomNumberBetween(20,400);
generate a random number between min and max
var min = 1;
var max = 90;
var stop = 6; //Number of numbers to extract
var numbers = [];
for (let i = 0; i < stop; i++) {
var n = Math.floor(Math.random() * max) + min;
var check = numbers.includes(n);
if(check === false) {
numbers.push(n);
} else {
while(check === true){
n = Math.floor(Math.random() * max) + min;
check = numbers.includes(n);
if(check === false){
numbers.push(n);
}
}
}
}
sort();
//Sort the array in ascending order
function sort() {
numbers.sort(function(a, b){return a-b});
document.getElementById("array_number").innerHTML = numbers.join(" - ");
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us