文档

获取一个0-1之间的随机数

// [0, 1)
console.log(Math.random());
// 0.7532061893284896

一个文档给出的示例

得到一个两数之间的随机整数

// [min, max)
function getRandomInt(min, max) {
    min = Math.ceil(min);
    max = Math.floor(max);
    // 不含最大值,含最小值
    return Math.floor(Math.random() * (max - min)) + min; 
}

console.log(getRandomInt(10, 100));
// 61