vendredi 14 octobre 2022

Random numbers generator which are not equal and Stackable in a 2Dimension Array

I want to get 6 not equal numbers into the first arrray [0][0-5] and then get 1 up and do the same with 6 not equal numbers [1][0-5] but the numbers from 0 and 1 can be equal. The code works with normal array but i tryd to make it 2d but is doesnt work. This is what i got so far. but doesnt work

for ( int a = 0; a < anzahlDerSpiele; a++){
    
    for ( int b = 0; b < 6; b++){
      zahlenRandom[a][b] = (double) (Math.random());
      zahlenRandom[a][b] = zahlenRandom[a][b] * 48+1;
      zahlenRandom[a][b] = Math.round(zahlenRandom[a][b]);
      boolean schonDrinne = false;            
      for (int j = 0; j < a; j++) {
        if (zahlenRandom[j][b] == zahlenRandom[a][b]) {
            schonDrinne = true;
            break;
        }
      }
      if (schonDrinne) {
        a--;     
      }
   }
}



Aucun commentaire:

Enregistrer un commentaire