In C (and your Python conversion), the <i>i < Random(1, 100)</i> part is evaluated each time through the loop, not once at start of the loop to determine the limit.<p>So, it’s 1% that the loop ends at <i>i = 1</i>, if it takes that hurdle 2% that it ends at <i>i = 2</i>,
if it takes that hurdle 3% that it ends at <i>i = 3</i>, etc.<p>The calculation is easier if you phrase that this way:<p>It’s 99% that the loop continues at <i>i = 1</i>, if it takes that hurdle 98% of the rest that it continues at <i>i = 2</i>,
if it takes that hurdle 97% that it continues at <i>i = 3</i>, etc.<p>So, the probability to make it past <i>i = n</i> is<p><pre><code> 0,99 × 0,98 × 0,97 × … × (1 - n/100)
</code></pre>
Note that this isn’t necessarily the case in all languages. Pascal, for example, has a real <i>for</i> loop where the limit is evaluated once and the index variable cannot be changed inside the loop, so that the compiler can determine the number of iterations before starting the first iteration.