JavaScript
[JavaScript] Math.random() - 난수발생
힘없는염소
2015. 2. 11. 11:06
// 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);}
반응형