JavaScriptNumberMath.random
Math.sqrt

Math.randomNumber

Math.trunc

Returns a floating-point, pseudo-random number between 0 and 1.

문법

Math.random()

예제

아래 값을 입력하면 예제에 즉시 반영됩니다.

const
Math
console
dice
const rand = Math.random();
console.log(rand);   // e.g. 0.7234567

// 1~10 사이 정수
const dice = Math.floor(Math.random() * 10) + 1;
console.log(dice);