0
Q:

random number in javascript

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

//usage example: getRandomNumberBetween(20,400); 
25
var random;
var max = 8
function findRandom() {
  random = Math.floor(Math.random() * max) //Finds number between 0 - max
  console.log(random)
}
findRandom()
7
var RandomNumber = Math.ceil(Math.random() * 100);              
// Returns a random number between 1 and 100
5

Math.floor(Math.random() * 100);     // returns a 
  random integer from 0 to 99
 
1
Math.floor(Math.random() * 5)   // print 0 to 5 && 5 not included

# it will give whole random number upto 5.
# you can add your lastIndex at place of (5).
# Math.floor() function returns the largest integer less than or equal to a given number.

1
Math.random() * 10 = 0-10
1
var randomNo = Math.floor(Math.rand() * 10000000001);
console.log(randomNo);

//This will generate random number
0
Math.random() returns a random number in [0,1)
0
function getTotal(){
    var total=0;
    for(let t=0; t<array.length; t++){
        total+= array[t].randomNum;
-1

New to Communities?

Join the community