When I call the randomCharge function below it always prints out "1" in the console log. This was confusing to me because I thought that "0" was inclusive and "1" was exclusive so if the range was "0" to "1", the Math.random function would never return "1"(this also being the Math.random default test). How is it possible to do that? Here is the code I am testing:
function randomCharge(min,max) {
return Math.random()* (max-min) + min;
}
var rand= Math.ceil(randomCharge(0,1));
console.log(rand);
Aucun commentaire:
Enregistrer un commentaire