### Having problems with random numbers

Hey I'm working on an exercise where the program creates five different sets of lottery numbers. Each set of numbers are supposed to contain unique numbers. I am using a 2-D int array to store the numbers, and also a 2-D bool array to mark true in the location of a number if it has already been used. I'm using a while loop to check the bool array and make sure the random number hasn't already been used. Here's my problem. I can print the random numbers but they're not always unique. I have been trying to figure this out for hours. PLEASE HELP!!!!
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364`` ``````//This is the lottery picker exercise from Tutorial 14 #include #include #include #include #include using namespace std; const int lottery = 4; const int number = 5; const int unique = 39; int main() { int selection = 0; int lotteryNumbers[4][5] = {0}; bool uniqueNumber[lottery][unique+1]; string lotteryNames[4] = {"First Lottery:\t","Second Lottery:\t","Third Lottery:\t","Fourth Lottery:\t"}; srand(time(0)); for (int i = 0; i < lottery; i++) { for (int d = 0; d < unique; d++) { uniqueNumber[i][d] = false; }//end second for cout << "\n" << left << setw(15) << left << lotteryNames[i]; for (int n = 0; n < number; n++) { do { selection = (1 + rand() % 39); }//end do while (uniqueNumber[i][selection] = false); uniqueNumber[i][selection] = true; lotteryNumbers[i][n] = selection; cout << left << setw(3) << lotteryNumbers[i][n]; }//end inner for }//end outer for cout << "\n\n"; return 0; }//end function main ``````
`while(uniqueNumber[i][selection] = false) `
must be:
`while(uniqueNubmer[i][selection] == false) `
Last edited on
whenever i ran
`while(uniqueNubmer[i][selection] == false)`
every number in the program was the same, even in different the different sets of numbers.
now run:
` while(uniqueNumber[i][selection] == true) `
the first one was a syntax bug, this one is logical
Last edited on
Oh and to make sure every thing is right, move the lotteryNumbers and uniqueNumber declarations outside the main functions, that way there are always initialized to 0 so you don't have to write a loop to do the initialization.
You sir, are a genius. I tried everything I could think of to get this to work even got as far as `while(uniqueNumber[i][selection] = true`, but it never occurred to me that I need 'is equal to' when dealing with booleans. I knew it was something small though, it had to be. Anyway, thank you very much. Now I can go to sleep. :)