A random journey through the math of gambling

The laws of chance are often subtle and deceptive. This is why games of chance work. People are convinced that they obey seemingly intuitive laws, while the underlying mathematical structure reveals a different and more complex reality. This article is a brief and rigorous journey through the implications that the mathematical laws governing stochastic processes have on gambling. It addresses a specific process, the random walk, and analyze some instances of fair and unfair games by highlighting the fallacy of many of our intuitions and beliefs. The paper gradually moves from the analysis of the random walk properties to a comprehensive description of the ruin problem. The introduction of the idea of transient and persistent states concludes the discussion. Much emphasis is placed on concrete examples and on the numerical values, in particular of the involved probabilities, and the interpretation of the results is always more central than the demonstrative technical details, which are nevertheless available to the reader.


Introduction
The simplest game of chance between two players is to flip a coin so that one wins on heads and the other wins on tails.Suppose the two players repeat the toss many times, and each time one loses, he or she gives the other a dollar.Of course, a player is considered a winner at some stage of the game if he has won more than he has lost.Now consider the question: What fraction of the total game time do we imagine one player will spend in the role of the winner, and what fraction in the role of the loser?Most people will probably respond that, being tossing a coin a '50%-50%' game, each player will spend about half the time leading and half the time losing.Indeed we are more or less convinced that we will spend part of the time as winners and part of the time as losers, and that this distribution will be somehow balanced.We also know that we cannot expect a 50% and 50% net split and that there will be some kind of fluctuation.Maybe we can expect to be in the lead 55% of the time and our opponent 45% of the time, or 48% against a 52%.In short, although we do not know what the exact split will be, we think it is most likely to be around half the playing time.
In the same way we are led to think that, if we start to loose, sooner or later we will break even and regain what we lost.But how many times can we a↵ord to lose and come back to zero?Are we sure that this can happen as often as we would like?
Furthermore, what if the coin is rigged and it is no longer a fair game?how should we adjust our expectations?in a sense, in this case, it is easier for us to imagine some kind of asymmetric behavior that makes us in the game more favorable or unfavorable depending on the point of view.
Let us mention here only one example that will be discussed in the text.Suppose our strategy is to quit the game when our total winnings reach a certain value A, or, alternatively, when we completely deplete the budget B that we decide to allocate to this game.We will see that if even the probability of winning at each step is only 5% below the 50% which is typical of a fair game, and the probability of losing is 5% higher, then the probability of winning A before losing all of B is substantially less than the probability of losing all of B before winning A. Suppose A and B are 3 dollars.Then the probability of losing all our small 3 dollars budget before winning other 3 dollars would be 65%, as opposed to 35% of winning all 3 dollars before losing them.If it were 10 dollars, this probability would rise to 89%, and the probability of losing would go up even more for higher bets.This article will attempt to shed light on these and some other similar questions and to show that issues are more subtle than they appear on the surface.It is designed for anyone who wants to get a clearer idea of the mechanisms that govern gambling and games of chance in their mathematical implications, which, as paradoxical, also become psychological.We begin with a seemingly unrelated problem, counting votes in an election between two candidates, and then describe the properties of the random walk in the case of a fair game.We then introduce the ruin problem and compute the probabilities mentioned above in both the fair and unfair cases.Finally, we conclude with some remarks on the persistence of the random walker's return to the origin.
Reading requires a certain amount of patience.The text deliberately aims for maximum accessibility combined with minimum mathematical rigor, so that there are no logical or narrative leaps.The mathematics used is essentially combinatorics and elementary probability.The reader will not find any 'it is clearly seen that' or 'it is left to the reader to demonstrate immediately' except in one or two places at most where things are really obvious.However, the reader will not find any proofs in the text.It was simply felt that all proofs should be placed in the appendix, so that the text is direct and aimed at understanding the ideas rather than analyzing the demonstrative details.The reader who wants to go deeper is thus directed to the appendix.Only one proof is kept in the text since it is very instructive.

The Ballot Problem
Let us imagine that, during the ballot for the election to an institutional o ce, there are two candidates P and Q and that the ballot proceeds by examining the voting records one by one.Of course, during the counting process, one candidate may be first in the lead and then the other may move ahead, and this switch may occur several times.The question we want to focus on is: What is the probability that, throughout the counting, there have always been more votes for P than for Q?
A good way to list the votes for each candidate, at each step n of the counting process, is as follows.We can mark on a blackboard a +1 when the vote is assigned to P and a 1 when the vote is assigned to Q.After n steps, we have a list where we filled in imaginary cells with a sequence of +1 or 1.The value assigned to each cell is completely random.We call the empty cells random variables and denote them by X i .We have n random variables that get the value +1 if the vote is assigned to P and the value 1 if the vote is assigned to Q: We are left with a sequence {X 1 , . . ., X n } given by the votes we get from the ballot at each step.Suppose that in the sequence we have p plus one (+1) and q minus one ( 1), and that n is the last step, or, equivalently, that we are interested only in what happened before step n.Of course, the partial sum is the number of votes by which P leads or trails just after the k vote is cast.Clearly we have S n = p • (+1) + q • ( 1) = p q and S k S k 1 = X k = ±1 with S 0 = 0, for any k = 1, . . ., n. Conversely, an arrangement {S 1 , . . ., S n } of integers satisfying S k S k 1 = ±1 can represent a potential voting record.Now the idea is to represent such an arrangement by a polygonal line whose k th vertex has ordinate S k and whose k th side has slope X k .This line is called path.Consider the simple example illustrated in Fig. 1: after the counting of five votes, that is n = 5, we have S n = 1.Therefore p + q = n = 5 and p q = S n = 1, which means p = 3 and q = 2.The figure represents the path of the counting process, or, in other terms, of the random process.Since at each of the n steps we have two possible directions, up or down, there exist 2 n di↵erent paths coming out from the origin in n steps to the end point (n, y), for an arbitrary, that is not fixed, integer y.If, on the other hand, the value of y is constrained to be of the type p q when x is equal to p + q, the number of possible paths is significantly reduced.In fact, if exactly p among the X k are +1 and q are 1, so that x = n = p + q and y = S n = p q, then the p places in which we can put the +1, can be chosen from the total n = p + q available places in n p = n q di↵erent ways.Therefore, this number is equal to and N x,y = 0 if x and y are not of the form x = p + q and y = p q.This means that there are exactly N x,y di↵erent paths from the origin to the point (x, y) = (p + q, p q). Now, the condition that there have always been more votes for P than for Q is equivalent to the fact that S 1 > 0, S 2 > 0, . . ., S n 1 > 0 and S n = y > 0, i.e. that the path is always positive.The fraction of all the N x,y paths, from the origin to point (x, y) = (p + q, p q), that are always positive is quantified in a well-known result, named after J. L. F. Bertrand (1887, see [2]), also called the Ballot Theorem: Proposition 2.1.If x > 0 and y > 0, i.e. n > 0 and S n > 0, the expected number of paths from the origin to the point (x, y) that are always positive, i.e. of the kind {S 1 , S 2 , . . ., S n = y} with S i > 0, 8i = 1, . . .n equals This lemma provides the probability that, if P is leading at step n, then it has always led at all previous steps.The complete proof of the Proposition 2.1 can be found in the appendix.Here we make a few remarks.First, let us consider again the example in Fig. 1.We said that x = n = 5, and y = S n = 1, so that p = 3 and q = 2. Then there are N x,y = 5 3 = 10 possible paths from (0, 0) to (5, 1), but only y x N x,y = 1 5 • 10 = 2 paths are always positive and they are the two sequences (0, 1, 2, 1, 2, 1) and (0, 1, 2, 3, 2, 1).Note that 1  5 is the slope of the straight line from (0, 0) to (5, 1) and it is the probability that P it has always led at the previous steps if he or she is leading at step n = 5.In general, the total number of possible paths from the origin to the point (x, y) is multiplied by the mean slope of the polygonal line, that is the slope of the straight line from the origin to that point.
The reversed path is then described by the partial sums of the X i 's in the reversed order, that is As can be seen in Fig. 2, the two paths are congruent, join the same endpoints and are obtained from each other by a rotation of 180 .Now proposition 2.1 can be reformulated in this way.If x, y > 0, the number of reversed paths {S ⇤ 1 , . . ., S ⇤ n } joining the point (0, 0) to (x, y) such that S ⇤ i > 0 for i = 1, 2, . . ., n is equal to y x N x,y .Note that asking for S ⇤ i > 0 is equivalent to asking for S n S n i > 0, i.e. S n > S n i , for i = 1, 2, . . ., n. Explicitly, this means S 1 < S n , S 2 < S n , . . ., S n 1 < S n .Geometrically speaking, we can say that the original version of the theorem is concerned with paths whose left endpoint is the lowest vertex, whereas the dual version of the theorem is concerned with paths whose right endpoint is the highest.
Back to the origin.Before concluding this section, we want to make some remarks about the special case where the endpoint is y = 0, i.e.where the two candidates receive the same number of votes p = q after n rounds of voting.This is equivalent to a path that returns to the origin after its random walk above or below the axis.Since it is impossible to return to the x-axis in an odd number of steps, or equivalently, we cannot have an odd vertex on the x-axis, from now on we will denote this point as (2n, 0) and we will be interested in paths that connect (0, 0) to a point (2n, 0) on the x-axis.With this choice p + q = 2n and p = q = n.Of course, the number of all these paths is N 2n,0 = 2n n .Let us first define L 2n the following number Proposition 2.2.The following statements hold a) The number of paths such that S 1 0, S 2 0, . . ., S 2n 1 0 and S 2n = 0 is equal to L 2n ; b) The number of paths such that S 1 > 0, S 2 > 0, . . ., S 2n 1 > 0 and S 2n = 0 is equal to L 2n 2 .
Now the question is: Is it truly as easy as it might seem to return to the origin?What is the likelihood of this happening after a candidate has been in the lead for the entire ballot count?We will see that such an event is indeed extremely unlikely.To show this, we move from the problem of a runo↵ between two candidates to a more abstract game that reproduces the same conditions.

Tossing coins
Let us now focus on a fair game, like flipping a coin to get heads or tails.Imagine that two friends P and Q decide to play the following game for a given period, let's say N = 20 days.Every day they toss a coin.If it comes up heads, P wins and Q loses; if it comes up tails, P loses and Q wins.The value of the random variable is then assigned day by day, and each of the two friends constructs his own random walk.
Indeed, compared to the votes cast for candidates P and Q, in this case we can make a a priori assumption about the probability of getting one or the other result.If we call p and q the two probabilities of getting head or tail, they will be the same: p = q = 1 2 .Suppose we decide that a particular random variable X i takes on the value +1 if heads comes out and the value 1 if tails comes out, then we can say that the probabilities of the random variable taking on either value are given by Therefore, we can represent any possible outcome of the N successive tosses of a coin-and so any possible path followed by the two players in the N days of their gameby a path of N sides starting at the origin.If we get heads, P goes up and Q down; if we get tails, P goes down and Q up.Conversely, each such path can be seen as representing the outcome of N tosses of a coin.We have already said that the total number of possible paths of this type is 2 N .The set of all these paths is called sample space.The sample space is the collection ⌦ of the 2 N paths {S 1 , . . ., S N } starting at the origin.Since we have no reason to think that one of the paths is preferred over the others, we can attribute probability 2 N to each one.
An event such as E = {two heads at the first two trials} must be interpreted as the aggregate of all sequences starting with S 1 = 1 and S 2 = 1.There are 2 N 2 such sequences, since the first two steps are predetermined.The probability of the event E is then P(E) = 2 N 2 /2 N = 2 2 = 25%.More generally, if k < N there exist exactly 2 N k di↵erent paths such that their first k vertices lie on a preassigned path {S 1 , . . ., S k }.Now let us imagine the motion of a particle along a vertical axis as an indicator that shows the cumulative gain at all times of the two players: for P , one unit step upward if the coin lands on head, one unit step downward if the coin lands on tail, and the opposite for Q.This particle performs a real random walk and its path {S 1 , . . ., S N } represents the space-time diagram of its motion.In particular, we shall say that • at time i we have a return to the origin if S i = 0, • at time i we have a first return to the origin if {S 1 6 = 0, . . ., S i 1 6 = 0, S i = 0}, • at time i we have a first passage through A if {S 1 < A, . . ., S i 1 < A, S i = A}.Since we will be primarily interested in a possible return to the origin and a return can occur only at even times, as we said, we set N = 2n.The following proposition lists the probabilities of some possible events we could be interested in.
Proposition 3.1.The following equalities hold: In words: the three events a) a return to the origin takes place at time 2n, b) no return occurs up to and including time 2n, and c) the path is non-negative between 0 and 2n have all the same probability 1 2 2n 2n n ; whereas, the two events d) the first return to the origin takes place at time 2n, and e) the first passage through 1 occurs at time 2n 1, have both the same probability We introduce this notation that will come in very handy in what comes next: which for p = q = 1 2 becomes In this section, we always refer to the specific case in Eq. (8).The probabilities of the cases a), b), and c) are then exactly u 2n and the probabilities of the cases d), and e) can be expressed as 1 2n u 2n 2 = u 2n 2 u 2n = 1 2n 1 u 2n .The proof of this proposition is in the appendix.Here we want to use this result to analyze one of the main statements of this reading.To do that, we need this definition: we shall say that the particle that moves according to the random walk spends the time from k 1 to k on the positive side if the k th side of its path lies above the x-axis, i.e. if at least one of the two vertices S k 1 and S k is positive.
Here it is our main theorem.
Proposition 3.2.Let p 2k,2n be the probability that in the time interval from 0 to 2n the particle spends 2k time units on the positive side and 2n 2k time units on the negative side.Then Again the reader can find the complete proof in the appendix.By Eq. ( 8), p 2k,2n can be given the following equivalent expression We want to stress now the importance of this result by means of the following remarks.
Remark 1.We intuitively feel that the fraction k n of the total time spent on the positive side is most likely close to 1  2 , i.e. that the particle spends half its time above the axis and half its time below it.But will this be true?It may seem paradoxical, but we will see that it is not, and that the opposite is true.
In fact, have a look at the following Table 1 which lists the values of the probabilities p 2k,2n as a function of 2k for 2n = 20 and at the Fig. 3 which represents the same probabilities for 2n = 20 and 2n = 100.Table 1.: Values of the probabilities p 2k,2n that a particle spends a fraction k/n of its time on the positive side, as a function of 2k for 2n = 20.As we can see, values close to k n = 1 2 are the least probable, whereas the highest probability is assigned to the extreme values k n = 0 and k n = 1.What does it mean?If we toss a coin 20 times, the probability p 10,20 that the particle spends half of its time in the positive side is 0.06 = 6%, whereas the probability that the particle spends all time on the positive side or all time on the negative side is 0.18 = 18%, three times the previous one.In general, the two extreme probabilities p 0,2n = p 2n,2n and p n,2n are given by and their ratio is given by We can use an important approximation of the factorials for very large values of n, called the Stirling approximation, by which we can observe that The ratio between the two extreme probabilities increases with the number of trials as p n, which means, for example, that for 2n = 200 trials, the probability of the particle spending all of its time on the positive side is ten times the probability of an equally distributed position above and below the axis.So we begin to realize that if we start winning, we will keep winning, but also that if we start losing, we will keep losing!and this with much greater probability than a more or less balanced alternation of wins and losses!Let us try to restate the same idea in a slightly di↵erent way.
Remark 2. The quantity p 2k,2n returns the probability that the particle spends exactly k/n of its time on one side, positive or negative.Now let us consider the probabilities that the particle spends at most or at least ↵/n, for a given ↵ 2 N, of its time on one side.The so called cumulative distribution function P(2k  2↵), ↵ 2 N, 0  ↵  n returns this probability and it is defined as It represents precisely the probability that the particle spends up to 2↵ time units in the positive side, i.e. at most 2↵ time units in the positive side and at least 2n 2↵ time units in the negative side.For instance, for the previous set of 2n = 20 trials the distribution function P(2k  2↵) is given in the following   The behavior shown in these plots is not coincidental, but represents a very general property of cumulative probability.In fact, these cumulative distribution functions follow a recurrent arcsin law, as stated by the following proposition.
Proposition 3.3.For 2n !+1, the cumulative distribution function P(2k  2↵) can be approximated by This formula returns with good approximation the probability that the time spent on the positive side is at most, or, equivalently, less than 2↵ with 0  2↵  2n.The following Fig. 5 compares exact results with results expected by the arcsin model: Let's be clear about the meaning of formula (15).Consider the case 2n = 20 and the value 2↵ = 6.The cumulative probability is approximately P(2k  6) ⇡ 40%.This is the probability that the particle spends at most ↵/n = 6/20 = 30% of its time on the positive side and at least 1 ↵/n = 14/20 = 70% of its time on the negative side.In other words, if the particle were a gambler, with a 40% probability it would spend no more than 30% of its time in the game in a winning role.It is a fairly high probability compared to the small fraction of time he plays as a winner!In this case, the gambler-let's say P -would be the less fortunate of the two, spending less than half of the game time in a winning role, i.e. he would lose more than he wins.Remark 3. Let us consider the event E 1 ={The player P is in lead less than 2↵ days}.This event can be reformulated as 2n are interpreted as fractions of the game time.This event has probability This is the approximate probability that player P spends less time than x in the positive region above the axis, i.e. in the role of winner.Suppose he is the less fortunate of the two players, so that x < 1 2 .The same can be said of course by swapping the roles of the two players: E 2 ={The player Q is in lead for less than 2↵ days}={Q is in lead for ⇢  x }.The latter event has the same probability as the former We cannot know a priori who is the unluckiest player.Consider the event that is {One of the players is in lead for less than 2↵ days}.We are assuming that x is less than half of the playing time so we are precisely considering the point of view of the least fortunate player, whoever he or she may be.The probability of event E is then Suppose P and Q decide to extend the game for a whole year, 2n = 365 days!During this year, we don't know which of the two, but one of the two players is the less fortunate one and is in lead for a fraction x < 1 2 of the year.Call this probability P(E) = p.We have and x, that is the maximum fraction of year in which the less fortunate player is in lead with probability p, is given by Let's try to give some numbers: if p = 0.05, then x = 0.00154 = 0.5625 d = 13.50 h.This means that, with probability 0.05, i.e. 1 out of 20 cases, the less fortunate player will be in lead at most for 13.50 hours and the more fortunate player will be in lead for at least 364 days and 10.5 hours.There is a not inconsiderable probability that the unluckiest player will be in the lead for only a tiny fraction of the year!For example, there is a 50% chance that the least lucky player will be in the lead for a maximum of 53 days.Let us notice that, when p ! 0, x !0, and, when p ! 1, x ! 1 2 .
Remark 4. What was shown in the previous remark has an interesting implication.
It says that frequently enormously many trials are required before the particle returns to the origin, or that it takes an enormous number of attempts for the less fortunate player to at least break even.This means that the path crosses the x-axis very rarely.
If we toss a coin for 2n times, the number of ties will be proportional to p 2n.It can be proved that the probability that, within the time 2n, the particle returns to zero exactly r times is given by In particular, u 2n = P 0 (0, 2n) = P 0 (1, 2n) > P 0 (2, 2n) > P 0 (3, 2n) > . . . .For instance, for 2n = 100, we have P 0 (0, 100) = P 0 (1, 100) = 7.96%, P 0 (5, 100) = 7, 17%, P 0 (10, 100) = 4.84%, P 0 (20, 100) = 0.73%, and P 0 (30, 100) = 0.014%.We have hitherto assumed that the two probabilities p and q were equal.This is indeed the case in a coin toss but we can imagine a random walk produced by a process in which the two choices are not equiprobable.We now want to extend our argument to the case in which p 6 = q but, in order to do that, we need some further results about the so called ruin problem, which is the topic of the next section.

The Ruin Problem
In the fair game of the previous section, p and q were interpreted as the probabilities of getting heads or tails on a coin flip.All in all, this idea is fairly intuitive because the two events are reasonably equiprobable.In the ballot problem p and q were numbers, the number of actual outcomes of a ballot on N repeated trials.However, the ratios p/N and q/N are frequencies, and, if N is large enough, they are the probabilities of the two di↵erent outcomes.From now on, p and q will directly represent the two probabilities that one of two possible results will come out at each repeated trial, that is, that a given random variable will symbolically take on the value +1 or 1.If each draw or roll is independent of the previous one, then in no way does one result a↵ect the next.Technically, it is said that we have a set of N independent and identically distributed random variables.
We are now in a position to give a more general and more formal definition of the classical random walk.The random walk in one dimension is the stochastic process described by the motion of a particle whose position, at each step, is where X k are independent and identically distributed (i.i.d.) random variables such that P(X k = 1) = p and P(X k = 1) = q, with p + q = 1.We can assume S 0 = 0, without losing anything in our reasoning.What we're going to study now is the behavior of the random walk in the presence of two barriers, that is, two di↵erent values of S n , let's say a positive y = A and a negative y = B, so that the random walk stops when it reaches one of these two values.For example, suppose one of two players P and Q stops gambling when he or she gets A wins or B losses in two-outcome game.This is called ruin problem and we want to find out the probability to reach y = A before y = B or viceversa and the mean duration of this process.We will start from the case p = q = 1 2 which is called unbiased since there is no drift toward the positive values or the negative values.Then, we will move to the biased, and more general, case, in which the two probabilities are di↵erent, p 6 = q.In both cases, we will study similar propositions but their consequences will be very di↵erent.
The unbiased random walk.Let us immediately state the following proposition.This is a well-known result and it can be easily extended to the case in which the particle does not start from (0, 0) but from a point (0, k), with k 2 [ B, A].For instance, the expected duration becomes The biased random walk.Now, let us change the game.Suppose we roll a die and we take one step forward if we get 5 or 6 and one step back if we get 1 or 2 or 3 or 4, so that p = 1 3 and q = 2 3 .In technical language we should say that we are extending the previous argument to the case of a sequence of Bernoulli trials with probability p of success and a probability q of failure, with in general p 6 = q, i.e. p, q 6 = 1 2 , p + q = 1.In other terms, we have X k i.i.d.random variables such that and we want to consider the biased random walk defined by Let us assume again S 0 = 0.In general we call unbiased the random walk if p = q and symmetric if A = B.Here now is the extension of Proposition 4.1 to the biased case. and The proof of propositions 4.1 and 4.2 is not elementary, and the reader who is not interested in rather technical details may omit their study.However, we want to bring attention to a substantial set of consequences, which we gather in the following remarks.
Remark 5. First, the unbiased random walk is a limiting case of the biased one for p, q ! 1 2 .This is proved in the appendix.
Remark 6.If q = 0 and p = 1, we have This means that we get A in A steps.Similarly, if q = 1 and p = 0, we have That is, we get B in B steps.
Remark 7. Let's go back to the P(S ⌧ = A) and P(S ⌧ = B).They are given by Eqs. 26, and, written as functions of ⇢ = q/p, they become In the symmetric case, i.e. for A = B, they are simply It is easy to show that they are equal only for ⇢ = 1; more in general, their behavior as functions of ⇢ is shown in the Fig. 7 for two di↵erent values of A = B.The farthest are the barriers with respect to the origin, the quickest is the change in probabilities.For instance, for A = B = 3 we need roughly speaking a ratio ⇢ = 4 to be almost sure not to get the gain at +3, whereas for A = B = 10 it is enough a ratio ⇢ = 1.5 to be almost sure not to reach our success at +10.Let us stress this point.A high value of ⇢ means that the probability q of a move down predominates.So when ⇢ is high, it becomes increasingly di cult to win.In fact, if ⇢ is about 4 in the case A = B = 3, it becomes practically impossible to win.In the case A = B = 10 a lower ratio ⇢ between q and p is enough to make it practically impossible to win.In fact, it is reduced to ⇢ = 1.5.
If our strategy is to stop when we win 10 dollars or when we lose 10 dollars, then the probability of reaching the win first before losing our budget becomes very very small as soon as the game becomes unfavorable to us.For example, it only takes a ⇢ = 2 to be virtually certain of losing $10 before winning $10!The following Table 4 can give us a deeper insight in the numbers involved.As we can see from Table 4, the probability of win for a gambler in an unfair game depends on the value of A. Suppose that A also represents the final payout if it is reached.If ⇢ = 51 49 , i.e. if he has only the 1% more to loose than to win, the probability to win 3 dollars is 47%, whereas the probability to loose 3 dollars is 53% but the probability to win 10 dollars decreases to 40%, whereas the probability to loose 10 dollars increases to 60%.This is much more conspicuous if we reduce the probability of win of the 10%, that is for ⇢ = 60 40 .In this case, the probability to win 3 dollars is 23%, whereas the probability to loose 3 dollars is 77% and the probability to win 10 dollars decreases to 2%, whereas the probability to loose 10 dollars increases to 98%.An imbalance of only 10% in favor of the casino counter produces a collapse in the value of the odds of winning to 2%!It must always be kept in mind that in an unfair game, the probability of losing a given amount of money is much higher than the probability of winning the same amount of money, and the larger the amount, the more noticeable the di↵erence between these probabilities.Fig. 8 shows clearly how the probability of win decreases with A for di↵erent values of ⇢.Remark 8. Let us focus now on the expected duration E[⌧ ] and study its behavior as a function of ⇢ = q/p and of the barrier values A and B. When A = B, i.e. with a symmetric barrier, the expected duration becomes and the Fig. 9 shows its shape as a function of ⇢ for three di↵erent values of A: It can be observed from the figure-and can also be proved-that each plot has a maximum for ⇢ = 1, i.e. p = q, and that its value, as expected, is A 2 .Of course, the plot has an intercept at the origin at A and goes asymptotically to A as ⇢ !+1.In the asymmetric case, the expected duration takes the form The behavior is not very dissimilar to the previous one.The intercept at the origin still coincides with the value of A and the asymptotic value with the value of B. The curve attains a maximum at a value of ⇢ > 1 if A < B and ⇢ < 1 if A > B. The value of the maximum expected duration grows with A and with B. Let us finally observe that the value of the expected duration is perfectly symmetric with respect to an exchange of the values of A and B.

Back again to the origin
In the previous discussion, we gained more insight into the biased case, where the probabilities of winning and losing are generally di↵erent.What we want to do now is to go back to the problem of returning to the origin for a random walk, analyzed in the section 2, in the case P(X k = 1) = p 6 = q = P(X k = 1).Studying the return to the origin of our random particle equals focusing on the event E ={The cumulative number of successes and failures are equal}.Of course, if at the k-th trial the cumulative numbers of successes and failures are equal, then k must be an even number, k = 2n and n trials must have resulted in success, the other n in failure.
Proposition 5.1.The following equalities hold: In other words, by Eq. ( 8) u 2n = 2n n p n q n , the two events a) a return to the origin takes place at time 2n, and b) the first return to the origin takes place at time 2n, have probabilities given by For instance, when p = 1 3 and q = 2 3 and we take 2n = 20, the values of the two probabilities are P(S 20 = 0) = 5, 43% and P(S 1 6 = 0, . . ., S 19 6 = 0, S 20 = 0) = 0, 29%.Let us notice that the last probability is 1/19 of the first one.
A matter of transient or persistent states.We now want to focus on a subtle issue.The event E related to a return of the random walk to the origin in any of the 2n-trials is interpreted as the fact the we loose all what we gained or viceversa we re-gain all what we lose.This event could happen a number of times after we started the game.Let us try to formulate the issue in simple words.How many times do we expect the event E to occur if the number of repeated trials increases?If we imagine repeating the trials ad infinitum, what can we say about the expected number of times E will occur?Although it may seem strange, we want to show that the event E will occur a finite number of times even if we repeat the trials ad infinitum.The return to the origin cannot happen infinitely many times.
We now state a theorem.This theorem could appear di cult to understand at first reading.What is more important to us is the subsequent argument, which is more of a proof of the theorem and, for this reason, we do not postpone to the appendix.
We will explain the meaning of this proposition gradually.In Eq. ( 8) we defined u 2n which is exactly the probability that a return to the origin occurs at time 2n.Here we are interested in a great number of repeated trials, so we suppose 2n big enough.Let us start by using Stirling's formula 2n n ⇠ 4 n p ⇡n , for n !+1, in order to write Let us notice that 1 , if p 6 = q, then 4pq < 1 so that u 2n !0 and P n u 2n converges faster than the geometric series with ratio 4pq.When p = q = 1 2 , u 2n !0 but P u 2n diverges as it is asymptotic to a divergent generalized harmonic series. 2 In the first case, when it converges, we can compute the value of the sum of the series.In fact, by setting x = 4pq and ↵ = 1 2 , and by using the following combinatorial identity and the classical expansion we have The last equality is justified by: (p+q) 2 = 1 ) (p q) 2 = 1 4pq.So we have just proved that, if p 6 = q, u := P +1 n=0 u 2n < +1, which equals saying u := 1 This is related to the fact that the product of two numbers whose sum is constant is maximum if the two numbers are equal. 2Let us observe that {u 2n } is not a probability distribution since P u 2n can be greater than 1.For instance, in our previous example, we have P u 2n = 3.Instead, we can interpret u 2n as the expectation of a random variable which equals 1 or 0 according to weather a return to the origin does or does not occur at 2n-trial.Hence P 2n j=0 u j is the expected number of occurrences of such a return in 2n trials.
We now invoke a celebrated theorem, named first Borel-Cantelli Lemma, to draw our conclusion.First Borel-Cantelli Lemma says that if the sum of the probabilities of the events P +1 n=0 P(E 2n ) is finite, then the probability that infinitely many events E 2n occur is 0, or P(lim sup n!1 E 2n ) = 0.
Let us explain the meaning of lim sup n!1 E 2n .We know that P(E 2n ) = P(S 2n = 0).If we consider [ +1 n=1 E 2n , we are taking all the events E 2n , for any 2n, from the first trial to the 'last' one, which is the infinite.In other words, we are taking all the possible returns to the origin E 2n from time 2n = 2 to infinite.If we consider [ +1 n=2 E 2n , we are taking all the events E 2n from time 2n = 4 to infinite.If we consider [ +1 n=N E 2n , we are taking all the events E 2n occurred from and after time 2n = 2N .In this way, we do not consider events occurred before time 2n = 2N , that is we are excluding events in the first stage of our experiment.Of course, when N increases, the number of events left decreases and we are restricting to the only events happened after such a time.Now let us imagine that 2N !+1.There will always be a certain number of events remaining after time 2N, however great that time may be.These events left are in the intersection of all the previous sets, obtained for each finite N .The set lim sup n!1 E 2n is exactly this intersection, the core of events left after each step in which we increase N .Formally, lim sup n!1 . Now the probability related to the core of events left after 2N is given by ).On the one hand, when N grows to infinity, [ +1 n=N E 2n becomes our core set, the intersection of all these sets, and so P [ +1 n=N E 2n becomes P(lim sup n!1 E 2n ).On the other hand, when N grows to infinity, P +1 n=N P (E 2n ) is finite for sure since P +1 n=1 P (E 2n ) is finite, as we proved above.This implies that the limit of the remainder series is 0, that is lim N !+1P +1 n=N P (E 2n ) = 0. Therefore, in the light of the inequality a few lines above, we deduce that also lim N !+1P [ +1 n=N E 2n = 0.This means only one thing: from a certain point forward, the probability of an event E 2n occurring is zero, or equivalently, that it can no longer happen that S 2n vanishes.The cumulative sums S 2n will vanish only finitely many times.The random walk will return to zero only in a finite number of times.When this happens, i.e. when, like in this case, we have only a finite number of returns to the origin, we say that the recurrent event E ={A return to the origin takes place at time 2n} is transient.
What does this theorem tell us about gambling?In gambling terms, it says that after a finite number of initial fluctuations around 0 the net gain will be positive and remain so if p > q or will be negative and remain so if p < q.
We now merge everything we have said so far, particularly in section 3, to demonstrate the probability that the random walk ever re-enters zero.The probability to reach A before B obtained in Eq. ( 26) is We can adapt this formula to the case in which S 0 = 1, B = 0 and A = N (equivalent to S 0 = 0, B = 1 and A = N 1)1 : As N !+1, the probability that the particle reaches N before 0 becomes lim Note that when N !+1, the upper bound barrier goes to infinity, that is it disappears.The probability that the particle reaches 0 before N is then P(S ⌧ reaches 0 before N|S 0 = 1) = 1 P(S ⌧ reaches N before 0|S 0 = 1) and, in the limiting case, it becomes In a similar way, we can prove that Just a few more steps and we are there.Let us call P i = P(S ⌧ ever returns i |S 0 = i) the probability that the random walk, starting from a point i, will sooner or later return to the same point.Then P 0 = P(S ⌧ ever returns 0 |S 0 = 0) = p • P(S ⌧ ever returns 0 |S 1 = 1) + q • P(S ⌧ ever returns 0 |S 1 = 1) If p > 1 2 we have If p < 1 2 we have In general, we have Note that P 0 represents the probability that the random walk, starting from zero, will sooner or later return to zero.We can conclude that • if p 6 = q then P 0 < 1 and the point 0 is a transient state, • if p = q then P 0 = 1 and the point 0 is a persistent state, This result is very significant.It implies that, if p 6 = q, the particle will pass a certain number of times from 0 and then will continue towards constantly positive or negative values according to the value of p and q.In other words, the probability that it returns to 0 more than r times tends to zero.In the case p = q, the probability that the particle returns to 0 more than r times remains equal to 1 and it will return infinitely many times to 0.
From all this we conclude that if a game of chance is unfavorable to us, because for us p is less than q, then after a certain finite number of fluctuations around zero in the early stages of the game, in which we have now won and now lost, it will eventually be our fate never to break even again, but to continue losing indefinitely!Let us note that in the previous remarks we also proved the following important relation between P 0 and u = P +1 n=0 u 2n .If we compare results in Eq. ( 35), u = 1 |p q| , and in Eq. ( 38), P 0 = 1 |p q|, we find out that Therefore, if u is finite then P 0 < 1 and the passage by the origin is transient; if P 0 = 1, u diverges and the passage by the origin is persistent.This result will remain valid in dimensions greater than one, as discussed in the Appendix B.

Conclusion
We conclude by summarizing some of the most important lessons about the unexpected dynamics of gambling that the study of the random walk has revealed so far.We first observed that, in a fair game, the probability of spending a very small or very large fraction of the time on the positive side, that is in the role of the winner, is much greater than the probability of spending half the time on that side, as our intuition might incorrectly suggest.Moreover, the di↵erence between the probabilities of the extreme cases and that of the 50% 50% case increases with the number of trials.It does not grow very fast, but it grows!We found that it grows as p N/2, where N is the number of trials.
We also learned that there is a probability of 1% that the less fortunate player will be in the lead for 30 minutes at most, over an entire year of play, while the more fortunate player will be in the lead at least for 364 days, 23 hours, and 30 minutes.There is a non-negligible probability that the unluckiest player will only be in the lead for a very, very small fraction of the year.But there is also a 50% probability that the unlucky player will be in the lead for only 53 days out of 365.
The probability of a tie is also very low.The hope of returning to 0 at least once, which would mean regaining what we lost as less fortunate players, is less than 8 cases out of 100 of repeated attempts, and the hope of returning to a tie several times becomes smaller and smaller.And all this in a fair game!When we moved to the unfair games, things got worse, as we might have expected.For example, we found that if our strategy is to quit the game when we win A dollars or when we lose our budget of B dollars, then the probability of reaching the win before losing our entire budget becomes very, very small when the game becomes even the slightest bit unfavorable to us.For example, it only takes a q/p = 2 ratio to be virtually certain of losing $10 before winning $10!Moreover, when again, the probability of loosing is double than the probability of winning and we take 20 trials, the values of the probability that we break even exactly at the end of the game is 5, 43% and the probability that is happens for the first time at the end of the game is only 0, 29%.As can be seen, the probability of breaking even at the end of the game is very low.
Finally, through a nontrivial argument, we proved that in a unfair game, although it may seem weird, the event related to a return to the origin is transient, that is it will occur only a finite number of times even if we repeat the trials ad infinitum.A return to the origin cannot happen infinitely many times.Only in a fair game, the probability that the random walk, starting from zero, will ever return to zero is equal to 1 and we are sure that it will, sooner or later, return to the origin.A to B having one or more vertices on the x-axis.Let t be the abscissa of the first of such vertices, that is S a = y a > 0, S a+1 > 0, . . ., S t 1 > 0, S t = 0. Then S a = y a , S a+1 , . . ., S t 1 , S t = 0, S t+1 , S t+2 , . . ., S b 1 S b = y b , is a path leading from A 0 to B and having T = (t, 0) as its first point on the x-axis.There is so a one-to-one correspondence between paths from A 0 to T and those from A to T , and so between paths from A 0 to B and those from A to B.
Proof of the main Proposition: S 1 could be ±1; but we are looking for positive paths, so it must be S 1 = +1.Now, we are in the point (1, 1) and we want to find out the number of paths from (0, 0) to the point (x, y) which neither touch nor cross the x-axis.By previous lemma, the number of such paths is equal to Here it is why.Let's have a look at the Fig. A2: • N x,y is the number of all possible paths from (0, 0) to (x, y); • N x 1,y 1 is the number of all possible paths from (0, 0) to (x 1, y 1), which is the same as the number of paths from (1, 1) to (x, y); • N x 1,y+1 is the number of all possible paths from (0, 0) to (x 1, y + 1), which is the same as the number of paths from (1, 1) to (x, y).
The set of all the paths from from (1, 1) to (x, y) that do touch the x-axis anywhere is in a one-to-one correspondence with the set of all paths from (1, 1) to (x, y), since they have to cross the x-axis in at least one point.This is established by reflection with respect to the x-axis of the initial segment of the path at the step where it first touches the x-axis.This number is given by N x 1,y+1 and it can be seen if we change the coordinate axes moving the origin to ( 1,1).So, now we have to subtract from the number of all paths from (1, 1) to (x, y) the number of paths that start in (1, 1) and end in (x, y) and that touches the x-axis in at least one point.Coming back to our language in terms of p and q and being x = p + q and y = p q, we have and the proposition is proved.

A.3. Proof of Proposition 3
Let us consider the space of paths of fixed length 2n.The total number of paths from (0, 0) to (2n, y), 8y, is 2 2n .We proved there exist ◆ paths from (0, 0) to (2n, 0), so the relation a) is proved.We have seen before that there exist L 2n 2 paths joining (0, 0) to (2n, 0) such that S 1 > 0, S 2 > 0, . . ., S 2n 1 > 0. Therefore there are twice as many paths such that S 1 6 = 0, . . ., S 2n 1 6 = 0 and the corresponding probability is 2L 2n 2 2 2n = 2 2n+1 L 2n 2 and this gives relation d).The number of paths such that S 1 0, . . ., S 2n 2 0, S 2n 1 < 0 is equal to the number of paths such that S 1 0, . . ., S 2n 3 0, S 2n 2 = 0 which is given by L 2(n 1) = L 2n 2 and again we obtain probability dividing by the total number of paths that, in this case, is 2 • 2 2(n 1) = 2 2n 1 because after 2n 2 we could go up or down.So again we get 2 2n+1 L 2n 2 and e) is proved.The probability that no zero occurs up to and including time 2n is complementary to the probability that there is a first return to the origin at any of the even times less than or equal 2n.So we have 1 (u 0 u 2 ) (u 2 u 4 ) • • • (u 2n 2 u 2n ) = u 2n and this proves b).Finally, the probability that we have paths such that S 1 0, . . ., S 2n 0 is complementary to the probability of paths with a first passage to 1 at any time less than or equal to 2n, and, as before, we get u 2n .Finally, to prove the last equality in d) and e) we have to take into account the combinatorial relation u 2n 2 = 2n 2n 1 u 2n .

A.4. Proof of Proposition 4
Let us observe at first that, if 2k = 0 or 2k = 2n, we have p 0,2n = p 2n,2n = u 2n according to point c) of proposition 3.1.Let 1  k  n 1.A particle that stays on the positive side for 2k > 0 time units and on the negative side for 2n 2k > 0 time units must pass through zero.Let 2t be the time of its first return to zero.We can have two cases depending on whether the particle was on the positive or negative side before 2t. 1) Up to time 2t the particle stays on the positive side and during the interval (2t, 2n) it spends exactly 2k 2t time units on the positive side: Then there exist 2 2t • (u 2t 2 u 2t ) paths of length 2t which return to the origin for the first time at 2t.It is the total number of paths 2 2t multiplied by the probability u 2t 2 u 2t given by point d) of proposition 3.1.Half of these paths keeps to the positive side: 2 2t 1 •(u 2t 2 u 2t ).Furthermore, by definition, there are 2 2n 2t •p 2k 2t,2n 2t paths of length 2n 2t starting at (2t, 0) and having exactly 2k 2t sides above the x-axis.Thus the total number of paths of length 2n of the first type is 2) From 0 to 2t the particle stays on the negative side, and between 2t and 2n it spends exactly 2k time units on the positive side: It follows that, for 1  k  n 1: Now let us suppose by induction that p 2k,2⌫ = u 2k u 2⌫ 2k for ⌫ = 1, 2, . . ., n 1.Then we have:

A.5. Proof of Proposition 5
Let us observe that, by means of the Stirling's approximation formula For n, k, ↵ !+1, we recognize the Riemann sum approximating the integral By setting ⇢ = cos 2 ✓ and ✓ = arccos p ⇢, we get and eventually we have In probability theory, a sequence of random variables for which, at any given time, the conditional expectation of the subsequent value is equal to the current one, regardless of any previous value, is called a martingale.This proof will use some properties of martingales, and we refer the reader to the text [8] for some of the technical details, particularly in reference to the stopped process and the stopping time theorem.The process S n is a martingale and, by the stopping time theorem, also S n^⌧ , the stopped process, is a martingale.It follows that E[S n^⌧ ] = E[S 0^⌧ ] = E[S 0 ] = 0 if S 0 = 0.So E[S n^⌧ ] = 0, 8n 0. We also ask that P(⌧ < +1) = 1, i.e. that ⌧ is finite with probability 1.Under this conditions: lim Let us define a new process M n := q p Sn , with M 0 = 1.The process M n is a martingale, since Finally, we get We have also The last expression is equivalent to P(S ⌧ = A) under the switch q $ p and A $ B.
To prove the expected duration, let us consider a new process: In the biased random walk we have E[X n ] = 1 • p + ( 1) • q = p q = 2p 1.So we define: =E[S n + X n+1 n(p q) (p q)|F n ] =S n n(p q) + E[X n+1 ] (p q) =S n n(p q) + (p q) (p q) =S n n(p q) = M n and we can apply stopping theorem for martingales.In fact we know that The E[⌧ ] may be given a more symmetric expression or A.8. Proof of the Remark after Proposition 4.2 If p = q then p ! 1 2 and q ! 1 2 , and we can consider an expansion of our functions around 1  2 .If we set we have that and which is equivalent to Thus we have 2B(p q) 2B 2 (p q) 2 2(A + B)(p q) B 2A(q p) 2A 2 (q p) 2 2(A + B)(q p) = AB p q  B(p q) + A(p q) A + B = AB this way, we have u Let us observe that we could have obtained this number also in the following way.Let us consider two strings a and b of +1 and 1 of length 2n, such that there is an equal number of +1 and 1 in each one.We want to construct a loop of length 2n.We can establish the following rules: the pair (a i , b i ) corresponds to the i-th step  In this way we have built a bijection between the loops in Z 2 and all the couples of plus and minus that we can build starting from two strings of 2n terms in which we have n plus and n minus, and this number is of course the product of the two binomials 2n n .Now, again for n !+1 by Stirling's approximation 2n n 2 ⇠ 4 2n ⇡n , we

Figure 1 .
Figure 1.: A simple example of possible outcome of the ballot counting.

Figure 2 .
Figure 2.: A simple example of reversed path.Blue line is the path S and red line (when non overlapping with S) is the reversed path S ? .

Figure 3 .
Figure 3.: Plot of the probabilities p 2k,2n that a particle spends a fraction k/n of its time on the positive side, as a function of 2k, (a) for 2n = 20 and (b) for 2n = 100.

Proposition 4 . 1 .
Let A, B 2 R, A, B > 0 and ⌧ = min{n 0 : S n = A or S n = B} be the first passage time through A or B. ThenP(S ⌧ = A) = B A + B , P(S ⌧ = B) = A A + B and E[⌧ ] = AB(23)The quantity P(S ⌧ = A) represents the probability that the random walk reaches A before B and similarly for P(S ⌧ = B); E[⌧ ] is the expected mean value of the time or of the number of steps needed to reach one of the two barriers.Let's have a look at the Fig.6, where A = 5 and B = 3.

Figure 6 .
Figure 6.: An illustrative example of the ruin problem for an unbiased random walk, with A = 5 and B = 3.

Proposition 4 . 2 .
Let S n be a biased classical random walk, A, B 2 R, A, B 0 and ⌧ = min{n 0 : S n = A or S n = B} be the first passage time through A or B. Then we have

Figure 7 .
Figure 7.: Plot of the function P(S ⌧ = A) = 1 1+⇢ A in red circle points and of the function P(S ⌧ = A) = 1 1+⇢ A in blue square points (a) for A = B = 3 and (b) for A = B = 10.

Figure 9 .
Figure 9.: E[⌧ ] as a function of ⇢ for three di↵erent values of A in the symmetric case: green triangle points A = 4, blue square points A = 3, and red circle points A = 2.

Figure
Figure A1.: Paths analyzed in the proof of the lemma

Figure
Figure A2.: Paths analyzed in the proof of the Proposition

•
in the direction (+1, 0) if (a i , b i ) = (+1, +1),• in the direction ( 1, 0) if (a i , b i ) = ( 1, 1).• in the direction (0, +1) if (a i , b i ) = ( 1, +1), • in the direction (0, 1) if (a i , b i ) = (+1, 1),This walk returns to the origin.In fact, let the number of pairs (+1, +1) be k, the number of pairs ( 1, 1) be l, the number of pairs ( 1, +1) be m and the number of pairs (+1, 1) be n, then k + m = l + n and k + n = l + m.Hence, 2k = 2l, i.e. k = l and m = n.So, the number of up steps is equal to the number of down steps and the number of right steps is equal to the number of left steps.

Table 2 .
: Values of the cumulative probabilities P(2k  2↵) as a function of 2k for 2n = 20.Data in Table 2, and the analogous ones for 2n = 100, are depicted in the Fig. 4.

Table 3 .
Table 3 collects similar results for x, expressed in days or hours, for di↵erent values of p. : Values of the probability p as a function of the fraction of year x, expressed in days.