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 and i don't want to use list, 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;
}
}