Sum of Random Variables... Imagine we repeat the following loop some thousands of times:
$$
\begin{align}
& \text{array} = []\\
& \text{for n} = 1: 10 000 \\
& k = 0 \\
& \text{while unifrnd}(0,1) < 0.3 \\
& k = k + 1 \\
& \text{end} \\
& \text{if k} \neq 0 \\
& \text{array} = [\text{array,k}] \\
& \text{end} \\
\end{align}
$$
whereas "unifrnd(0,1)" means a random number drawn from the uniform distribution on the unit interval.
My question is then: What is then the value of k, which is the most often observed - except for k = 0? And is that the expectation of k?
Thanks very much

It appears you exit the loop the first time the random is greater than $0.3$.  In that case, the most probable value for $k$ is $0$.  It occurs with probability $0.7$.  The next most probable is $1$, which occurs with probability $0.3 \cdot 0.7$, because you need the first random to be less than $0.3$ and the second to be $0.7$.  In general, the probability of a value $k$ is $0.3^k\cdot 0.7$
