JS生成随机数
function generateRandomNumber() {
let numbers = Array.from({ length: 10 }, (_, i) => i); // 生成一个包含0到9的数组
let randomArray = [];
for (let i = 0; i < 12; i++) {
if (numbers.length === 0) {
// 如果数组用尽,重新填充
numbers = Array.from({ length: 10 }, (_, i) => i);
}
const randomIndex = Math.floor(Math.random() * numbers.length);
const digit = numbers.splice(randomIndex, 1)[0];
randomArray.push(digit);
}
return randomArray.join('');
}