1️⃣ Math.random() 0 ≤ x <1 구간에서 부동소수점의 난수를 생성할 수 있다. [Javascript] Math 메서드 (+속성) 2️⃣ 특정 범위 내의 난수를 생성하는 방법 min ≤ 난수<max *min이 정수가 아닌 경우에는 min보다 큰 최소의 정수 function getRandomArbitrary(min, max) { return Math.random() * (max - min) + min; } 3️⃣ 정수 난수를 생성하는 방법 Math.random() (난수 생성 함수)와 Math.floor(x) (버림 함수)를 함께 사용한다 특정 범위 내의 정수 난수를 생성하는 방법 min ≤ 정수 난수<max function getRandomInt(min, max) { min = Math.c..
[Javascript] 난수 생성하기 (범위 지정, 정수 난수 생성)
1️⃣ Math.random() 0 ≤ x <1 구간에서 부동소수점의 난수를 생성할 수 있다. [Javascript] Math 메서드 (+속성) 2️⃣ 특정 범위 내의 난수를 생성하는 방법 min ≤ 난수<max *min이 정수가 아닌 경우에는 min보다 큰 최소의 정수 function getRandomArbitrary(min, max) { return Math.random() * (max - min) + min; } 3️⃣ 정수 난수를 생성하는 방법 Math.random() (난수 생성 함수)와 Math.floor(x) (버림 함수)를 함께 사용한다 특정 범위 내의 정수 난수를 생성하는 방법 min ≤ 정수 난수<max function getRandomInt(min, max) { min = Math.c..
2023.03.31