I'm trying to write a random number game in JavaScript, but I'm having a lot of trouble with getting the random number to actually generate something in between min and max if they're changed.
This is what I have so far:
var min = 1,
max = 10;
function randomNumber() {
var val;
do {
val = Math.round(Math.random() * max);
} while (val<=(min - 0.5));
return val;
}
However, if I change min and max, the numbers just don't really work out.
I'd appreciate any help, thanks.
Aucun commentaire:
Enregistrer un commentaire