乱数を取得
function getRandomInt(max) {
return Math.floor(Math.random() * max);
}
使用例
let test = 5;
print(getRandomInt(5)); // 0~5の整数の中からランダムに出力
最小値・最大値を両方指定する場合
function getRandomIntMinMax(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min) + min);
}
使用例
let min = 1;
let max = 5;
print(getRandomIntMinMax(min, max)); // 1~5の整数の中からランダムに出力