Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

get random number with min and max

const randomNumber = getRandomNumberBetween(1,1000)
const getRandomNumberBetween = (min, max) => {
    return Math.floor(Math.random() * (max - min + 1) + min)
}
Comment

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(" - ");
}
Comment

random between min and max

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

PREVIOUS NEXT
Code Example
Javascript :: searching in json array mongodb 
Javascript :: getDataSnapshotFirebase 
Javascript :: how to remove child element in jquery 
Javascript :: mongodb replace root 
Javascript :: repeat array in js 
Javascript :: javascript file on select 
Javascript :: script tag inside react component 
Javascript :: export gcp credentials json file 
Javascript :: http request javascript 
Javascript :: check if an element is there in js 
Javascript :: recursion in javascript 
Javascript :: downgrade node version 
Javascript :: parse string to int nodejs 
Javascript :: js split string every n characters 
Javascript :: jquery on scroll 
Javascript :: js get node index 
Javascript :: nodejs open file 
Javascript :: js add a tag inside span 
Javascript :: sequelize migration skeleton 
Javascript :: map list in javascript 
Javascript :: substr() javascript 
Javascript :: javascript time script 
Javascript :: javascript toggle button 
Javascript :: looping through an array javascript sum 
Javascript :: read multiple parameters in url in js 
Javascript :: javascript href on load delay 
Javascript :: angular new component 
Javascript :: select2 find option by text 
Javascript :: prime number in javascript 
Javascript :: convert a string to number in javascript 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =