const indRandom = (n, maxValue, minValue = 0) => {
const nNumArray = [...Array(maxValue + 1).keys()];
const resultArray = [];
for (let i = 0; i < n; i++) {
const randomNum = Math.floor((Math.random() * (((maxValue - minValue) + 1) - i)) + minValue);
resultArray.push(nNumArray[randomNum]);
nNumArray.splice(randomNum, 1);
}
console.log(resultArray);
return resultArray;
};
indRandom(5, 10000);
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
闭关修行中......