1function randomNumber(min, max) {
2 return Math.floor(Math.random() * (max - min)) + min;
3}
1var random;
2var max = 8
3function findRandom() {
4 random = Math.floor(Math.random() * max) //Finds number between 0 - max
5 console.log(random)
6}
7findRandom()
1//Returns a number between 1 and 0
2 console.log(Math.random());
3
4//if you want a random number between two particular numbers,
5//you can use this function
6 function getRandomBetween(min, max) {
7 return Math.random() * (max - min) + min;
8 }
9//Returns a random number between 20 and 170
10 console.log(getRandomBetween(20,170));
11
12//if you want a random integer number from one number to another
13//(including the min and the max numbers), you can use this function
14 function getRandomIntBetween(min, max) {
15 min = Math.ceil(min);
16 max = Math.floor(max);
17 return Math.floor(Math.random() * (max - min + 1)) + min;
18 }
19
20//Returns a random integer number from 0 to 25
21 console.log(getRandomIntInclusive(0,25));
1function getRandomNumberBetween(min,max){
2 return Math.floor(Math.random()*(max-min+1)+min);
3}
4getRandomNumberBetween(50,80);
5
6
1function randomInteger(min, max) {
2 return Math.floor(Math.random() * (max - min + 1)) + min;
3}
1var options = ["Your options", "Another option!", "This is an option."];
2var chosenOption = Math.floor(Math.random() * options.length);
3console.log(options[option]);