finding duplicates in an array

juancferrer

Senior member
Oct 7, 2002
254
0
0
i've got 5x5 array "player1[5][5] (bingo card). Each element of the array is a random #. Column 1: 1-15, Column 2: 16-30, etc. I want to find if there are =duplicate numbers in each column, and if there are, call this function that'll generate a random number.

right now i have this...and it fills the array with the right numbers

for(int x=0;x<5;x++)
{
for(int y=0;y<5;y++)
{
//Random returns a random #. if x=0, returns 1-15, x=1, 16-30, etc.
player1[x][y]=Random(x);
player2[x][y]=Random(x);
}
}

I've been trying to do another for loop and what not to find the duplicate numbers, but i just haven't been able to figure it out.
 

Zugzwang152

Lifer
Oct 30, 2001
12,134
1
0
I would keep an array of numbers already selected, and for each new Random() call, iterate through the array and see if its in there. If it is, repeat the process. If not, use it and add it to the array.
 
Sep 29, 2004
18,656
67
91
Originally posted by: Zugzwang152
I would keep an array of numbers already selected, and for each new Random() call, iterate through the array and see if its in there. If it is, repeat the process. If not, use it and add it to the array.

The easier way is to keep an array of booleans. Initially all false. Use the indices to map to the numbers. Then when one is chosen, set the bool to true. make an algorithm (or class in C++) to handle this.