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

You can model your process as a random walk with unit steps in the positive direction. In other words, define independent random variables $Z_i$, $i \in 1, 2, n$ such that:
$P(Z_i = 1) = \frac{1}{3}$ and
$P(Z_i = 0) = \frac{2}{3}$
Set the initial position of the walk as $S_0 = 0$ and define:
$S_i = S_0 + \sum_{j=1}^iZ_j$ 
Your question then reduces to investigating the behavior of the random variable $S_n$. Specifically, you are asking for the mode of $S_n$ and $E(S_n)$.
By linearity of expectations, it can be seen that:
$E(S_n) = \frac{n}{3}$
My intuition suggests that the mode will coincide with the mean.
