I have this number generator, which generates me a 2d matrix with random values. The values in column 4 and 5 are either 1, 3, 7 or 20. But when column 4 is a 1, column 5 should be either 3, 7 or 20 (they should never have the same values).
I tried it with the double x and double y declaration under the second for-loop, but that doesn't work. So in my next try, I would try it with a do-while-loop, but I don't know, how to implement that loop in my code.
public class HelloWorld{
public static void main(String[] args) {
Number[][] values = new Number[10][26];
for (int i = 0; i < values.length; i++) {
for (int j = 0; j < values[i].length; j++) {
double x = Math.random();
double y = x < 0.25 ? 1 : x < 0.5 ? 0.74 : x < 0.75 ? 0.49 : 0.01;
if (j == 0) {
values[i][j] = Math.random() < 0.5 ? 0 : 1;
} else if (j == 1) {
values[i][j] = (int)Math.floor(((Math.random() * (250000000 - 500000)) + 500000));
} else if (j == 2) {
values[i][j] = (int)(Math.random() * (23)) + 1;
} else if (j == 3) {
values[i][j] = x < 0.25 ? 1 : x < 0.5 ? 3 : x < 0.75 ? 7 : 20;
} else if (j == 4) {
values[i][j] = y < 0.25 ? 1 : y < 0.5 ? 3 : y < 0.75 ? 7 : 20;
} else {
values[i][j] = Math.floor(Math.random() * 100000) / 100000;
}
System.out.print(values[i][j] + " ; ");
}
System.out.println();
}
}
}
Aucun commentaire:
Enregistrer un commentaire