js获取0-1之间的随机数,获取1-10之间的随机数

//获取0-1之间的随机数
var num = Math.random();
console.log(num);
//获取1-10之间的随机数
var num = Math.floor(Math.random() * 10) + 1;
console.log(num);

获取两个数之间的随机整数

//可取 start 不可取end
function getRandomNumberByRange(start, end) {
    return Math.floor(Math.random() * (end - start) + start)
}
getRandomNumberByRange(0,100)
// 可取start 可以取到end
function getRandomNumberByRange(start, end) {
    return Math.floor(Math.random() * (end - start+1) + start)
}
function randown() => Math.floor(Math.random() * (end - start+1) + start)