Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- Programming
- Windows 10
- game
- webhard
- web
- 대항해시대
- Backup(Restore)
- network
- PC
- LiveCD(USB)
- Update
- H/W
- Disk Partition
- calculator
- MS windows
- javascript
- FTP
- portable
- Network Info(Tool)
- SSH
- MS Windows PE
- apm
- Linux
- Crack(Serial Key)
- UNIX
- script
- explorer
- OS(operating system)
- Command
- program
Archives
- Today
- Total
<In Story>
자바스크립트 정수 난수만들기, Javascript Random(integer) // [Programming] [Script] [Web] [JavaScript] 본문
Programming/Web
자바스크립트 정수 난수만들기, Javascript Random(integer) // [Programming] [Script] [Web] [JavaScript]
<In Story, Hi story, History> 2015. 10. 4. 19:12http://rankingis.com/?titlequery=자바스크립트-난수-랜덤-숫자-만들기-예제
http://mwultong.blogspot.com/2006/11/random-javascript.html
Math.floor(Math.random() * 100) + 1;
이렇게 하면, 1에서 100까지 나오고
Math.floor(Math.random() * 10);
이렇게 하면, 0에서 9까지 나오게 됩니다.
그럼 100에서 200까지의 난수를 구하려면 어떻게 할까요?
위 예제와 거의 같으나 최소값은 100이고 최대값은 200이 되겠죠?
function randomRange(n1, n2) {
return Math.floor(Math.random() * (n2 - n1 + 1)) + n1;
// Math.floor(Math.random()*(101)) + 100;
// Math.floor(Math.random()*(최대값-최소값+1)) + 최소값;
}