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
 A: 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$
A: Since the events "unifrand(0,1) > 0.3" (which lead to a repetition of the same value of $k$) can come in any order and all these orders are equally likely, there is no special value of $k$ that occurs most often. 
Edit: With the code as it reads now, the value $k = 1$ will be the most frequent one, and $k$ has indeed a geometric distribution.  
A: 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.
A: if you want the number that is most likely to be made out of a sum like this. you need combinations to get that sum * probability of each combination. So, 
$${n\choose m}*.3^m*.7^{n-m}$$ 
should be maximized. according to wolfram alpha this is not exactly .3*n http://www.wolframalpha.com/input/?i=maximise+%28choose%28200%2Cn%29.3^n.7^%28200-n%29%29
that's the best I can do.
Edit: You changed your question, and I anticipate one more change at least. I think you are looking for the expected value of k, rather than the most often observed value. So here is how you calculate that:
$$\sum_{n\to \infty }{n*Pr(n)}$$ where $$Pr(n) = .3^n$$
let $r=.3$ and we can psuedoexpand our series (to make it clearer what we are doing) to: $$ r+2r^2+3r^3+...$$ or $$r+r^2+r^3+...$$ $$r^2+r^3+...$$ $$r^3+...$$
then we have ${\frac{r}{1-r}}+r{\frac{r}{1-r}}+r^2{\frac{r}{1-r}}+... = {\frac{r}{(1-r)^2}}=30/49$ which is probably the answer you want...
