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
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$.