english

Math

let random = Math.random() * 10;
random = random.toPrecision(3);
alert("랜덤값 : " + random);

const ceil = Math.ceil(random);
alert("올림값 : " + ceil);

const floor = Math.floor(random);
alert("내림값 : " + floor);

const round = Math.round(random);
alert("반올림 : " + round);

로또번호 생성기 자바스크립트 버전

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.toString());
참고