JavaScript数値Math.random
Math.sqrt

Math.random数値

Math.trunc

0 以上 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);