function sectionRandom (start, end) { let nums = end - start + 1 return Math.floor(Math.random() * nums + start) } sectionRandom(1, 5) sectionRandom(2, 8)
JS 在区间内取随机数
6 min read
function sectionRandom (start, end) { let nums = end - start + 1 return Math.floor(Math.random() * nums + start) } sectionRandom(1, 5) sectionRandom(2, 8)