I've got a logical problem with my mathematics skills. so far, I have to calculate a prizing system to say "you won" or "you lose".

here my way until now:

  • u = max. users
  • p = prizes
  • w = winchance in percent: p*100/u

to say, if you won or not I use this:

$win = (rand(0,10000) > 100*(100-w)) ? TRUE : FALSE;

is this the correct way to calculate it? or is there still a better solution? thanks a lot, ~frank

  • $\begingroup$ Does max.users u=10000 ? $\endgroup$ – CAGT Jan 22 '14 at 8:31
  • 1
    $\begingroup$ Minor problem for rand: if $w=100$, there is still slight chance for the code to give a FALSE. I suggest changing the rand part to rand(1,10000). Bigger problem, but maybe still minor: rand might be giving integers only, so if the right hand side of inequality $100\times(100-w)$ is not an integer, the result may not be precise. $\endgroup$ – peterwhy Jan 22 '14 at 9:21

Apart from the problem of the random function I wrote above, the logical problem here is that the result from every run of the code is supposed to be independent. And so, if $w$ is fixed and the code is run for $u$ times, the number of wins follows binomial distribution: $$W\sim B\left(u,\frac pu\right)$$

And while the expected number of wins is $p$, there is quite some chance that the resultant number of wins is different from $p$. Actually, $$P[W\neq p] = 1 - \binom{u}{p}\left(\frac pu\right)^p\left(1-\frac pu\right)^{u-p}$$

If $p$ is fixed and $u$ approaches infinity, the distribution converges to Poisson distribution with expected number of wins $p$. The probability

$$P[W\neq p]\approx 1-\frac{p^p}{p!}e^{-p}$$

For $p=1$ and $u=10000$, there is over $63\%$ chance that the number of wins is not equal to your $p$.

  • $\begingroup$ could you please explain this in "my words"? like I did with $win = .... cause my skills in mathematic syntax is to low to understand you. I've got the % of the winchance, so how can I say: you win or lose, based on the % winchance? $\endgroup$ – frank allen Jan 22 '14 at 9:52
  • $\begingroup$ In short, you can almost keep your code $win=(rand(1,10000) > 100*(100-w)) ? TRUE : FALSE;, but the problem of this logic is that the number of wins after running the code for $u$ times is not guaranteed to equal to $p$. $\endgroup$ – peterwhy Jan 22 '14 at 9:57
  • $\begingroup$ in my example, I startet with 4 prizes and 10 users, after a few runnings, I had 3 prizes left for 3 users, so it's a 100% chance to win? $\endgroup$ – frank allen Jan 22 '14 at 10:03
  • $\begingroup$ OK, if you modify $u$ to "number of remaining users" and $p$ to "number of remaining prices", that would be better. $\endgroup$ – peterwhy Jan 22 '14 at 10:08

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.