Q:

random number generator js

var random;
var max = 8
function findRandom() {
  random = Math.floor(Math.random() * max) //Finds number between 0 - max
  console.log(random)
}
findRandom()
7
function randomNumber(min, max) {
  return Math.floor(Math.random() * (max - min)) + min;
}
11
var options = ["Your options", "Another option!", "This is an option."];
var chosenOption = Math.floor(Math.random() * options.length);
console.log(options[option]);
0
  let replies = [
    "1",
    "2",
    "3",
    "4",
    "5",
    "6",
    "7",
    "8",
    "9",
    "10",
    "11",
    "12"
  ];

  let result = Math.floor(Math.random() * replies.length);
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.floor(Math.random() * 10);     // returns a random 
  integer from 0 to 9
 
0
function getRandomArbitrary(min, max) {
  return Math.random() * (max - min) + min;
}
0

Math.random()
1
Math.random() returns a random number in [0,1)
0

New to Communities?

Join the community