编写一个js方法3个参数第一个参数最小值第二个参数最大值 第三个参数数量返回当前区间的数量随机数
function randomNum(min, max, count) { let result = []; for (let i = 0; i < count; i++) { result.push(Math.floor(Math.random() * (max - min + 1)) + min); } return result; }
// 示例 console.log(randomNum(1, 10, 5)); // [3, 7, 6, 5, 1] console.log(randomNum(1, 100, 10)); // [45, 36, 83, 16, 35, 95, 76, 70, 32, 67]
原文地址: http://www.cveoy.top/t/topic/fEfQ 著作权归作者所有。请勿转载和采集!