I'm writing a program for a simple gambling machine simulation with configurable expected return and variance.

For a given stake, the machine always pays out a return of either {nothing, 2:1, 5:1, 20:1, or 100:1}

The expected return to player value is a configurable variable. For example, if it were 95%, the player would expect the machine to payout \$9,500 for having played a \$1 stake 1000 times.

The variance of the machine is also a configurable value, from some preset list of sensible values. A machine with a low variance value would pay out regular, smaller wins, whereas a machine with a high variance would payout fewer, bigger wins.

Given an RTP and variance value, I need a way of calculating sensible probabilities for the payouts. Obviously, the probabilities should be strictly decreasing as the payout increases, and I'd imagine decreasing in some kind of exponential/logarithmic manner (although I'm not sure about that).

I'm not really sure how to go about doing this. Any help or pointers would be greatly appreciated!

Please excuse the wording, I'm not from a maths background so I hope I'm describing the problem clearly enough.


This is just a suggestion. It's hard for me to know how it would work out in practice without some actual values for expected return to the player and the variance. I can guess that the expected return is somewhere in the neighborhood of $95\%$, but I have no idea about the variance.

Any, for $k=2,5,20,100$ let $p_k$ be the probability that the machine returns $k$ on a $1$ bet, let $\mu$ be the desired return, and let $\sigma^2$ be the desired variance. We have $$\begin{align} \mu&=2p_2+5p_5+20p_{20}+100p_{100}\\ \sigma^2&=4p_2+25p_5+400p_{20}+10000p_{100}-\mu^2 \end{align}$$ If you set the values of $2$ of the probabilities, you will have $2$ linear equations in $2$ unknowns. I presume there are customary values for $p_2$ and $p_5$ or at least, that you can guess what reasonable values would be. Then solve for $p_{20}$ and $p_{100}$ and see if the values are reasonable. Or perhaps it would be better to start from the other end, assigning values for $p_{100}$ and $p_{20}$ since the variance will be sensitive to these probabilities.


Let $X$ be the outcome of playing the machine (here $X$ is a 'random variable'). So $X$'s can be payoffs $x_1, \ldots, x_n$ each with a corresponding probability $\pi_1, \ldots, \pi_n$. If you are only given the mean and variance, that's 2 constraints on $2n$ variables, so you're correct that there will be many solutions (you've also got the constraint that the $\pi_i$'s must sum to 1, but let's put that on the back burner for now).

If you're given two values, a mean and variance, and want to solve for the payoffs and probabilities, you can basically freely choose the payoffs and probabilities except for 2 of them. The last two get the values necessary to make these equations hold:

$$E(X) = \mu = \sum_i \pi_i x_i $$ $$\implies \sum_i \pi_i x_i - \mu = 0$$ $$Var(X) = \sigma^2 = E(X^2) - E(X)^2 = \left(\sum_i \pi_i (x_i)^2\right) - \mu^2 $$ $$\implies \sum_i \pi_i (x_i)^2 - \sigma^2 - \mu^2 = 0$$

One way to find a solution is to start picking values until you only have 2 left, and those last 2 are computed from your previous choices, the given expectation, and the given variance.

That being said, if you add more constraints on the values then you will have less freedom on the choices, which is maybe want you want for a more structured game. For instance, maybe the game doesn't have $n$ completely independent payoffs, rather the payoffs are $\{0, x, 2.5x, 5x, 10x, 50x\}$ Now one choice of $x$ fixes all the payoffs. Maybe the probabilities must have certain relationships with each other, like $\pi_2 = \frac{1}{2}\pi_1$. Then you could write $\pi_2$ as $\frac{1}{2}\pi_1$ in the summations above, and that's effectively one less variable. If you put more relationships like this on the problem it will narrow down your free choices but give the game more structure.

  • $\begingroup$ Thank you for the write-up! It makes sense how to calculate the expectation and variance if the probabilities are known, however in my situations the expectation and variance are already known and the probabilities must be 'calculated'. From what I understand there could be many values for the set of probabilities that would satisfy a given Expectation/Variance pair, so I guess what I'm really after is a way to generate some reasonable set of probabilities that would satisfy the constrains. $\endgroup$ – Daniel Messias Mar 27 at 17:47
  • $\begingroup$ Gotcha, I think. I edited to address solving for the distribution given the mean and variance. $\endgroup$ – BBrooklyn Mar 27 at 21:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.