我正在写一个彩票申请。我有一个名为generateLotteryNumbers
this 的函数,它接收一个数组并用 5 个随机数填充该数组。我想要做的是让这个函数在每次调用这个函数时产生一组不同的随机数。
void generateLotteryNumbers(int lotteryNumbers[])
{
srand (time(NULL));
const int arraySize = 5;
int index = 0;
while (index < arraySize)
{
lotteryNumbers[index] = rand() % 50 + 1;
cout << lotteryNumbers[index] << endl;
index++;
}
}
目前的输出是例如:
5
24
45
26
47
重复了两次。