1、代码及思路整理
/**
* 封装函数,函数名 getRandomNum(min,max,countNum)
* 生成 min~max 范围的 countNum 个不重复的随机数,存入数组并返回
*/
//生成指定数目和范围的随机数
const getRandomNum = function (min, max, countNum) {
var arr = [];
// 在此处补全代码
for (i = 0; i < countNum; i++) {
let ss = Math.floor(Math.random() * (max - min +1) + min)
arr.push(ss)
}
return arr;
}
module.exports = getRandomNum; //请勿删除
2、涉及到的知识点
(1)随机数公式【max-min之间,包括max和min】
Math.floor(Math.random() * (max - min + 1) + min)
(2) push方法【数组追加元素】
arr.push(ss)