Expected outcome of a process following a uniform distribution [closed]

A gambler is playing a game of roulette. There are $$37$$ possible outcomes, each numbered from $$1$$ to $$37$$. The probability of rolling any outcome is the same for each outcome. One game of this roulette is $$N$$ spins. Once the person picks a number, he has to stick with it to the end (if the gambler runs out of money, it is allowed for him to finish the game with a negative amount - it is not necessary to stay strictly positive throughout all the spins played). A win gives the gambler $$36$$ dollars, a loss takes $$1$$ dollar away.

1. Given, that the gambler starts with $$50$$ dollars, what is the expected probability that the gambler will be left with a sum of money $$> 0$$ after a game with $$N=\{100, 1000, 100000\}$$ spins?

2. What is the expected value after $$N$$ spins?

1. I have written a simple function in R that generates the process of the gambler's money flow.
library(tidyverse)

roulette <- function(p, bank, n) {
roulette <- round(runif(n,0,36),0)
vault <- vector(length = n+1)
vault[1] <- bank
for (i in 1:n) {
if (roulette[i] == p) {
bank <- bank + 36
} else {
bank <- bank - 1
}
vault[i+1] <- bank
}
return(list(value=roulette,money=vault,result=vault[n]))
}


Using this function I generate $$100000$$ games with $$N = 100$$ and draw a histogram with all the final outcomes.

r <- replicate(100000, roulette(7, 50, 100)\$result)

r %>% as.data.frame() %>%
ggplot(aes(x=.))+
geom_bar()+
theme_bw()



Which results in:

And calculating the proportion of outcomes with a result $$> 0$$ gives me:

> length(r[which(r>0)])/length(r)
[1] 0.52124


$$N = 100$$:

> length(r[which(r>0)])/length(r)
[1] 0.51903


However, when $$N = 100000$$, the mean of the outcomes (and the proportion of outcomes with a result $$> 0$$) shifts dramatically:

> length(r[which(r>0)])/length(r)
[1] 0.92709


1. My intuition tells me, that the expected outcome after a game with $$N$$ spins should be close to the gamblers starting money, which in this case is $$50$$ dollars.

closed as off-topic by jbowman, Peter Flom♦Apr 2 at 12:06

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – jbowman, Peter Flom
If this question can be reworded to fit the rules in the help center, please edit the question.

• One crucial aspect that you don't describe in your post, is the payoffs here. How much money does the gambler plays in each spin? How much money does he wins when his chosen number comes up? – Alecos Papadopoulos Apr 1 at 18:39
• @AlecosPapadopoulos Yes, my bad, I have edited the post accordingly. Thank you. – O. City Apr 1 at 18:51
• Clarify the first question please: does it mean "to stay strictly positive throughout all the spins played"? – Alecos Papadopoulos Apr 1 at 19:37
• With "allowed for him to finish the game with a negative amount" I implied that it is not necessary to stay strictly positive throughout all the spins played. – O. City Apr 1 at 19:45
• @gunes Yes, I understand my error, now I get the expected results. Thank you very much, I will pay more attention to my RNG from now on. I had to change the correct answer because otherwise it would have been off-topic. – O. City Apr 4 at 10:55

For your first question, let $$I_k$$ be a Bernoulli random variable taking the value $$1$$ if the gambler wins in spin $$k$$, and zero otherwise. Then

$$W_k = I_k\cdot (W_{k-1}+36) + (1-I_k)\cdot (W_{k-1}-1) = W_{k-1} +37I_k-1$$

By repeated substitution, we get

$$W_k = W_0-k + 37 \sum_{i=1}^kI_i$$

So we have expressed the random variable $$W_k$$ as a function of deterministic terms and the sum of independent RVs. Good. Then we ask for the probability, for some $$k$$,

$$P\big[W_k>0\big] = P\left[W_0-k + 37 \sum_{i=1}^kI_i>0\right] = P\left[ \sum_{i=1}^kI_i>\frac {k-W_0}{37}\right]$$

$$=1-P\left[ \sum_{i=1}^kI_i \leq \frac {k-W_0}{37}\right]$$

This is the probability that we are asked to calculate, for various values of $$k$$. The sum of independent Bernoullis does not have a closed form distribution, but it obeys the Central Limit Theorem after suitable centering and scaling, and so maybe one would want to use the Normal approximation (or go by simulation of course).

For your second question, this is why these are not the odds actually holding in a casino:

Let the spin index $$k=1,...,N$$. Let $$W_0$$ be the original amount of money, and let $$W_k$$ be the amount of money the gambler will have after spin $$k$$. Assume that we have arrived at that moment. Then the conditional expected value is

$$E[W_k|k-1,k-2,..,1] = \frac {36}{37}\cdot (W_{k-1}-1) + \frac {1}{37}\cdot (W_{k-1}+36) = W_{k-1}$$

$$\implies E(W_k) = E\big[E[W_k|k-1,k-2,..,1]\big] = E(W_{k-1})$$

Since $$k$$ was arbitrary, it follows that the the expected value is constant throughout and equal to the original amount of money (set $$k=1$$). By the way the first line above is the defining property of a martingale.

• This is very helpful, expressing the random variable as a function cleared up a lot for me. Thank you! – O. City Apr 2 at 16:04

Your random number generation is not correct, because of the edge cases. Probability of getting $$0$$ or $$36$$ is half of probability of getting other numbers. For example, to get $$0$$, it needs to create a random number in $$[0,0.5]$$, but to get $$1$$, it needs to pick a number in the range $$[0.5,1.5]$$, which is twice the former.

The following needs to be changed as follows:

round(runif(n,0,36),0) $$\rightarrow$$ floor(runif(n,0,37))

Because of the above situation, one spin has the expectation $$E[X]=36\times\frac{1}{36}+(-1)\times\frac{35}{36}=\frac{1}{36}$$ $$N$$ spins (since they're independent) will have an expected revenue of $$N/36$$, which explains the shift in your last graph: $$100000/36\approx2778$$.

Normally, the expectation of one spin is $$E[X]=0$$ (if you calculate as above), with correct probabilities, i.e. $$1/37$$. And, the expected value will be $$0$$, and you'll be where you start actually.

Also, you don't use $$50$$ dollars anywhere in your code. For your first question, starting with no money, and asking for final money to be $$>0$$ is easy (and will be $$0.5$$ if you use the correct random number generator); however, asking for $$>0$$ when your start money is $$50$$ is a bit harder one to answer.

Edit: Since you edited your question back to original $$50$$ dollars initial condition, we can think as follows:

For $$N=100$$ spins, the probability of $$X>-49$$, where $$X$$ is our total earnings, is actually not losing more than $$49$$ dollars. If you win more than once, you'll be guaranteed to have more than $$0$$ dollars net. So, remove the probability of losing all the time and just once from $$1$$: $$P(\text{Money}>0)=1-\left(\frac{36}{37}\right)^{100}-{100 \choose 1}\frac{1}{37}\left(\frac{36}{37}\right)^{99}\approx 0.75$$

For $$N=1000$$, the situation is harder. We need to win $$26$$ times or more to be on positive side. So, it's going to be a formula involving sums: i.e. $$\sum$$'s. Maybe, it's better to expect an approximate solution here, using Central Limit Theorem:

One spin has $$\mu=0, \sigma=6$$. $$N$$ of them will have $$\mu=0,\sigma=6\sqrt{N}$$: $$P(X>-50)=P\left(Z>-\frac{50}{6\sqrt{N}}\right)=1-\Phi\left(\frac{50}{6\sqrt{N}}\right)$$ For $$N=1000$$, you'll have $$P(X>-50)\approx 0.6$$ for example.

• This makes sense, thank you! I jumped back and forth between leaving it with the original starting 50 dollars and 0 just to make the question simpler. Changed the code, but decided to leave the initial condition. Will edit the code. (The generated histograms follow the condition of starting with 50 dollars). – O. City Apr 1 at 19:38