i want to generate random numbers without duplicate from 1 to n^2 (e.g. n=3, numbers in range of 1 to 9) in 2D array, but my code generated the numbers duplicate, how can i fix this ? here is my code :
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
array[i][j] = rand.nextInt((n * n) - 1) + 1;
}
}
Aucun commentaire:
Enregistrer un commentaire