Another question. This one is about loops and arrays in a function.
I have to generate 5 unique lottery numbers in the range of 1 to 50 inclusive.
This is what I have:
1 2 3 4 5 6 7 8 9
void generateLotteryNumbers(int lotteryNumbers [])
{
int index = 0;
for (int counter = 0; counter < 5; counter++)
{
lotteryNumbers[index] = rand()%50 + 1;
index++;
}
}
It generates my 5 lottery numbers just fine, however, run it a few times, and eventually you get two numbers that are the same.
I tried doing a really complicated for - do - while loop that said for 5 iterations do generate random lottery numbers, while the newest one is == to the last one generate a new number , but it didn't work, then I tried a do - while loop that was kind of similar. I even just tried a for loop with an if statement, which worked, but would give me a very small statistical probability of generating the same number twice, and I think part of the point of this exercise is validation to make sure they are all unique.
Any help is appreciated.