Math
let random = Math.random() * 10;
random = random.toPrecision(3);
alert("Random: " + random);
const ceil = Math.ceil(random);
alert("Ceil: " + ceil);
const floor = Math.floor(random);
alert("Floor: " + floor);
const round = Math.round(random);
alert("Round: " + round);
The following JavaScript code generates a lotto number.
const lotto = new Array();
let index = 0;
while(true) {
let check = true;
let ball = Math.random() * 45;
ball = Math.floor(ball) + 1;
for (let i = 0; i < lotto.length;i++) {
if (lotto[i] == ball) {
check = false;
break;
}
}
if (check) {
lotto[index++] = ball
}
if (index > 5) {
break;
}
}
alert("Lotto number: " + lotto.toString());
References
