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 :: back button not working when modal open in react native 
Javascript :: react native elements bottom sheet 
Javascript :: google maps color pin 
Javascript :: send embed with webhook in JS 
Javascript :: use obj property inside itself 
Javascript :: load images js context 
Javascript :: javascript modify href attr 
Javascript :: regular expression javascript 
Javascript :: vuejs nested v-for 
Javascript :: How to Check for an Empty String in JavaScript by String Comparison 
Javascript :: js addeventlistener keyup android 
Javascript :: node js create pdf from html 
Javascript :: react hook useeffect 
Javascript :: script defer attribute 
Javascript :: window close function in javascript 
Javascript :: Create Your Vue Project 
Javascript :: get search value from reacr route3 
Javascript :: express req.body empty 
Javascript :: time zone browser javascript 
Javascript :: Google App Script getSheetByName 
Javascript :: nodemon.json env 
Javascript :: javascript change first letter to uppercase 
Javascript :: persistent bugger javascript code 
Javascript :: parse string javascript 
Javascript :: get file extension of path extendscript 
Javascript :: useref react class component 
Javascript :: formgroup angular 
Javascript :: repeating countdown timer javascript 
Javascript :: nestjs framwork 
Javascript :: Removing borderline of input in react 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =