I need to make an array (matrix) with random numbers but without any dupplicates an also with some conditions. I have this code, It can make ramdom numbers without repetition but I have a variable called DifferentNumber and the ramdom number must be different of that number
Matriz2[0][i] = (int) (Math.random() * range);
for (i = 1; i < cantidad; i++) {
Matriz2[0][i] = (int) (Math.random() * range);
for (int j = 0; j < i; j++) {
if (Matriz2[0][i] == Matriz2[0][j]) {
i--;
}
}
}
For example, DifferentNumber = 25 And the matrix must go from 0 to 45 without repetition and being different of 25 something like this:
Matrix [0][0] = 26
Matrix [0][1] = 1
Matrix [0][2] = 40
Matrix [0][3] = 39
I hope you can help me and I hope I didn't make any mistakes I'm not an english native speaker
Aucun commentaire:
Enregistrer un commentaire