//To genereate a number between 0-1
Math.random();
//To generate a number that is a whole number rounded down
Math.floor(Math.random())
/*To generate a number that is a whole number rounded down between
1 and 10 */
Math.floor(Math.random() * 10) + 1 //the + 1 makes it so its not 0.
// Returns an integer between min and max (the maximum is exclusive and the minimum is inclusive)
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min) + min);
}
// min value of the random number
var min = 5;
// max value of the random number
var max = 25;
// generate the random number
var rdm = (Math.random() * (max - min)) + min
// generate the random number without "."
var rdm = Math.round((Math.random() * (max - min)) + min)
let randomNum = Math.floor(Math.random() * 5)
return( 0 or 1 or 2 or 3 or 4)
let randomNum = Math.floor(Math.random() * 5) + 1
return( 1 or 2 or 3 or 4)
// * 5 in this code meaning a number between 0 and 4
/*
`Math.random` returns a pseudo-random number between 0 and 1.
a pseudo-random number is generated by an algorithm, it is not
technically actually random, but for all intents and purposes
it is random enough that no human should be able to find a
pattern
*/
Math.random(); // -> Decimal number between 0 and 1
Math.round(Math.random()); // -> 0 or 1
Math.random() * max; // -> Decimal number between 0 and max
Math.floor(Math.random() * max); // -> Whole number between 0 and max - 1
Math.round(Math.random() * max); // -> Whole number between 0 and max
Math.ceil(Math.random() * max); // -> Whole number between 1 and max
(Math.random() * (max - min)) + min; // Decimal number between min and max
Math.floor((Math.random() * (max - min)) + min); // Whole number between min and max - 1
Math.round((Math.random() * (max - min)) + min); // Whole number between min and max
Math.ceil((Math.random() * (max - min)) + min); // Whole number between min + 1 and max
Math.random() * Math.random(); // Decimal number between 0 and 1 with a tendency to be smaller
1 - Math.random() * Math.random(); // Decimal number between 0 and 1 with a tendency to be larger
//To genereate a number between 0-1 - > this will give you float 0.1569491123 - 0.98799941612
Math.random();
// Generated number can be rounded with -> Math.floor
Math.floor(Math.random())
/*To generate a number that is a whole number rounded down between
1 and 10 */
Math.floor(Math.random() * 10) + 1 //the + 1 makes it so its not 0.
/*
To generate a random number between a and b keep in mind this formula:
a-> minimum value
b->maximum value */
let randomNumber = a+(b-a)*Math.random();
/*this gives you any random number between a and b
*/
var random = Math.floor (Math.random() * 10) + 1;
//This generates a number between 10 and 1
example.children[random].innerHTML = random;
//This displays the number on screen
var options = ["Your options", "Another option!", "This is an option."];
var chosenOption = Math.floor(Math.random() * options.length);
console.log(options[option]);