Math
var random = Math.random() * 10; random = random.toPrecision(3); alert("Random: " + random); var ceil = Math.ceil(random); alert("Ceil: " + ceil); var floor = Math.floor(random); alert("Floor: " + floor); var round = Math.round(random); alert("Round: " + round);
The following JavaScript code generates a lotto number.
var lotto = new Array(); var index = 0; while(true) { var check = true; var ball = Math.random() * 45; ball = Math.floor(ball) + 1; for (var 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