Regrettably, I was not diligent in attending my probability classes at school, unlike you, I hope. Nevertheless, your query simplifies to:
- What are the chances of completing the operation less than 4 times? (0 since a result greater than 4 is expected, requiring at least 5 operations),
- And what are the odds of repeating the operation more than 20 times, considering a 20% chance per operation to meet the condition?
This holds true regardless of the number of tests.
The following code snippet may help you in calculating the probabilities you seek:
var result = [];
var j=0;
for (j;j<1000000;j++){
var summe = 0;
var i = 1;
while(summe < 4){
summe += Math.random();
// document.write(i + ") " + summe + "<br>");
i++;
}
result.push(i);
}
const matchingResult = result.filter(num=>num<=20 && num>4);
// Alternatively, simplified as const matchingResult = result.filter(num=>num<=20);
console.log(matchingResult.length/10000,"%","between 4 and 20");
console.log(result.filter(num=>num>20));
I trust this information proves beneficial! ;)