-
javaScript) 랜덤(난수) 생성하기Programing Language/JavaScript 2021. 5. 20. 10:48728x90반응형This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
// (1) 0 <= random < 1 const rand1 = Math.random(); document.write('(1) ' + rand1 + '<br>'); // (2) 0 const rand2 = Math.floor(Math.random()); document.write('(2) : ' + rand2 + '<br>'); // (3) 0 <= random <= 9 const rand_0_9 = Math.floor(Math.random() * 10); document.write('(3) : ' + rand_0_9 + '<br>'); // (4) 0 <= random <= 10 const rand_0_10 = Math.floor(Math.random() * 11); document.write('(4) : ' + rand_0_10 + '<br>'); // (5) 0 <= random <= 99 const rand_0_99 = Math.floor(Math.random() * 100); document.write('(5) : ' + rand_0_99 + '<br>'); // (6) 0 <= random <= 100 const rand_0_100 = Math.floor(Math.random() * 101); document.write('(6) : ' + rand_0_100 + '<br>'); // (7) 1 <= random <= 10 const rand_1_10 = Math.floor(Math.random() * 10) + 1; document.write('(7) : ' + rand_1_10 + '<br>'); // (8) 2 <= random <= 5 const rand_2_5 = Math.floor(Math.random() * 4) + 2; document.write('(8) : ' + rand_2_5 + '<br>'); 728x90반응형'Programing Language > JavaScript' 카테고리의 다른 글
javaScript) 정규 표현식 모음 정리 (0) 2021.05.28 javaScript) input 태그 포커스 인/ 아웃 이벤트 캐치하기 (0) 2021.05.27 javaScript) map 자료형 for문 사용하기 (0) 2021.05.20 CSS+HTML)부모 div영역의 높이에서 이미지와 텍스트 수직 정렬하기 (0) 2021.04.10 CSS) Div안에 텍스트 가운대 위치시키기 (0) 2021.04.10