Probability analysis and implementation

Hey there,
I realize this is mostly a math and statistics problem, and if this is a bad place to seek help, please just point me in the right direction, but since these are questions about probability as implemented in a c++ program, I figured this would be a good place to start.

So I have a program that I've built that deals with games of chance, and one of the functions for it displays stats from a list of previously played games. I'm not very good with probability, but I'm starting to get a handle on it after doing some research recently, but I could still use some guidance at this point. What I do know is the probability of each game individually, but in trying to aggregate the probability of the games together, I'm running into some confusion. What I'm trying to do is figure out the expected wins. And for my own edification, I'd like to know what that actually means as far as probability goes. I would also like to calculate the probability of the next win occurring (or x wins), not on an individual basis, which is known already and not affected by previous wins/losses, but overall.

I've seen it said that if you play a single number on a roulette table, on average you can expect to win once if you play 38 times (on a US table). Of course, this is not a certainty, but on average it will happen. That's what I mean by "expected." So if we scale that down to a dice roll, you could say if you roll a die 6 times, on average you will get a 6 once. As I understand it, as far as probability goes, ((total_outcomes - losing_outcomes) / total_outcomes) in this case would be ((6*6*6*6*6*6) - (5*5*5*5*5*5)) / (6*6*6*6*6*6) = (46,656 - 15,625) / 46,656 = 0.6651, which means it will happen about 2/3s of the time. So then, does "on average" or "expected" mean that the probability is 2/3s? If not, what then? The probability of rolling a 6 after 5 rolls is about 60% and it doesn't drop below 50% until we go down to 3 rolls. So doesn't that mean I should "expect" to roll a 6 after 4 rolls, since there will be a better chance than not that it will happen? And if not, then where is the "expect" boundary? Using the roulette table example, it would take the full 38 spins to be "expected" on average. But don't you have a greater than 50% chance after only 20 spins? If so, where do we set the boundary of expectation, in terms of probability, for any given sequence of games of chance? Is it 2/3s or 1/2? Or is it that we just sum the individual probability of each instance until it reaches 100%? That's what it would seem based on the above statement about roulette, which means in this case (or all of them?) an expected win occurs at 67% probability.

Now, as far as my program is concerned, I'd like to figure out what the expected numbers of wins is given x number of games (each with varying probability), and also what the probability of another win occurring is, given the actual (not expected) number of wins. I also need some help as far as the computation is concerned because I have a feeling the numbers are going to get too large for the average computer to calculate, even with long double. I know, in theory, how to calculate the probability of 1 win occurring using the equation above, but once I get passed 1, I'm not sure how to go about it. What is the probability of 2 wins occurring, 3, 4, etc? And how can this realistically be implemented with a list of over 100 games (and growing)? The multiplication will get very large pretty quickly.

As of right now I have been calculating the expected wins by summing the probability of each individual game and every time it crosses 100% I add 1 to the expected wins. Is this wrong? It doesn't seem to be, based on the roulette statement. But at the same time, I realize that the roulette statement is only true, on an individual basis, 67%(?) of the time, so how does that actually affect expectations? Does that mean I should multiply the sum by 0.67 (assuming this is a constant) to get a more accurate expectation?

So in summation (hardy har-har), I'd like to get a better understanding of probability equations and how to implement them (realistically) in a large scale stat analysis of hundreds of games, how to calculate the expected wins, what that means as far as probability, what the probability of an additional win is (given the actual number of wins), and on a related note, how to calculate the probability of x wins occurring, given an ever growing set of games to analyze. And I need to be able to do this without a super-computer, using long double at most.

TIA
Last edited on
As I understand it, as far as probability goes, ((total_outcomes - losing_outcomes) / total_outcomes) in this case would be ((6*6*6*6*6*6) - (5*5*5*5*5*5)) / (6*6*6*6*6*6) = (46,656 - 15,625) / 46,656 = 0.6651, which means it will happen about 2/3s of the time.

What will happen about 2/3's of the time?

You might see a similar number here:
https://www.boundless.com/finance/textbooks/boundless-finance-textbook/introduction-to-risk-and-return-8/understanding-return-76/expected-return-340-3795/

Note that it's significance isn't what you think it is. Didn't bother reading the rest.
"Expectation" has a very precise meaning in probability theory: it can be computed as
sum( X * Probability of X)
where the sum is over all possible values that X can take.

For equally-likely individual outcomes:
Probability(Something) = ( number of outcomes satisfying Something ) / ( total possible number of outcomes)

For multiple, independent events (like roulette wheels) probability of a sequence of events can also be computed by multiplying the probabilities of the individual members of that sequence.

And then there is statistics ... that is more about estimating unknown parameters (like population means) from small samples. However, if you can determine the parameters - as you ought to be able to do from a "fair" roulette wheel, then there is no need for this.


Beyond that, I think if you need advice on this forum I would
(a) have some sample code;
(b) be more specific (and brief) about what you actually need.

I would concentrate on understanding probability theory first.
Last edited on
I know, in theory, how to calculate the probability of 1 win occurring using the equation above, but once I get passed 1, I'm not sure how to go about it. What is the probability of 2 wins occurring, 3, 4, etc? And how can this realistically be implemented with a list of over 100 games (and growing)? The multiplication will get very large pretty quickly.



Every trial is either WIN or LOSE ... with a given probability p of winning on that trial.

The number of wins in n independent trials is then distributed according to the binomial distribution B(n,p). For large n there are either Poisson or normal approximations to this.

You can google "Binomial Distribution". You can even find some random-number simulations of it in header <random>.
Topic archived. No new replies allowed.