See the Pen Math.random() by nilgi (@nilgi) on CodePen.
Math.random()은 0~1 사이 난수를 표시하는데 다른 명령어와 사용하여 랜덤한 정수를 표시할 수 있다.
• Math.random() + Math.floor()
document.getElementById("mrmf").innerHTML = Math.floor(Math.random() * 10);
document.getElementById("mrmf1").innerHTML = Math.floor(Math.random() * 10) + 3;
• Math.random() + min, max
getRndInteger(0,24)
function getRndInteger(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
getRndInteger(0,24)
function getRndInteger(min, max) {
return Math.floor(Math.random() * (max - min + 3)) + min;
}