I think I don't have good understanding how Random numbers works. In the following sample I am trying to increment 200 counters with 25% probability. It works fine , I understand this is how it supposed to work, but I don't understand why presence of internal loop doesn't affect a probability for a specific counter. Why probability doesn't decrease?
public void test() {
int array[] = new int[200];
for (int i = 0; i < 1_000_000; i++) {
for (int j = 0; j < 200; j++) {
int one = ThreadLocalRandom.current().nextInt(100) + 1;
boolean res = one <= 25;
if (res) {
array[j]++;
}
}
}
System.out.println(Arrays.toString(array));
}
Aucun commentaire:
Enregistrer un commentaire