1//To genereate a number between 0-1
2Math.random();
3//To generate a number that is a whole number rounded down
4Math.floor(Math.random())
5/*To generate a number that is a whole number rounded down between
61 and 10 */
7Math.floor(Math.random() * 10) + 1 //the + 1 makes it so its not 0.
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// min value of the random number
2var min = 5;
3
4// max value of the random number
5var max = 25;
6
7// generate the random number
8var rdm = (Math.random() * (max - min)) + min
9
10// generate the random number without "."
11var rdm = Math.round((Math.random() * (max - min)) + min)
1//Write the following code to get a random number between 0 and n
2Math.floor(Math.random() * n);
1function getRandomArbitrary(min, max) {
2 return Math.random() * (max - min) + min;
3}
4
1/*
2To generate a random number between a and b keep in mind this formula:
3a-> minimum value
4b->maximum value */
5let randomNumber = a+(b-a)*Math.random();
6/*this gives you any random number between a and b
7*/