// Math 객체의 random()메서드를 이용
for( var i = 0 ; i < 10 ; i++) {
// Math.random()은 0.0000...~ 0.9999..까지 중의 실수를 반환한다. (1을 생성하지 않는다)
// Math.floor()함수로 소수점 이하는 버린다.
// Math.floor(Math.random()*(최대값-최소값+1))+최소값
var num = Math.floor(Math.random()*(10-5+1))+5; // 5~10까지 난수 발생
console.log(num);
}


반응형
Posted by 힘없는염소