I have an array ( cards) of 52 maps (13x4) and another array ( cardsOut) of 25 maps (5x5). I want to copy elements from 52 cards to a 25-card array randomly.
Also, I don't want duplicates in a 5x5 array. So here is what I have:
double row=Math.random() *13;
double column=Math.random() *4;
boolean[][] duplicates=new boolean[13][4];
pokerGame[][] cardsOut = new pokerGame[5][5];
for (int i=0;i<5;i++)
for (int j=0;j<5;j++){
if(duplicates[(int)row][(int)column]==false){
cardsOut[i][j]=cards[(int)row][(int)column];
duplicates[(int)row][(int)column]=true;
}
}
2 problems in this code. First, random values ββfor a row and column are generated only once, so the same value is copied to the 5x5 array each time. Since the same values ββare copied every time, I'm not sure if my double check is very efficient, or if it works at all.
How to fix it?
source
share