+ 2
Is Math.random is necessary? If yes give me some idea where ti use it mo plss.. 😊 THANKKSS
Where Math.random use for?
2 Respostas
0
It is used if you want to generate a random value between 0 and 1.
0
It can be used to generate random chances. Example:
function randomChance(num) {
return Math.random() > 1 / num;
}
It is also possible to generate other random numbers too:
function random(min, max) {
return Math.random() * (max - min) + min;
}
function randInt(min, max) {
return Math.floor(Math.random() * (max - min) + min);
}
// Maximum is exclusive