In my problem, p$p$, X$X$, and N$N$ are fixed and I want to know the probability. Currently, I am calculating this recursively, as for any given p$p$,X $X$,N $N$, the probability is:
function Prob(p,X,N) {
return p*Prob(p,X-1,N-1) + (1-p)*Prob(p,X,N-1)
}
The intuition behind this is that if we were successful (first term) we have X-1$X-1$ more successes to find and N-1$N-1$ more trials. If we weren't successful (1-p)$(1-p)$, we have X$X$ more successes to find and N-1$N-1$ more trials.
There are also base cases that I left out where X=0$X=0$ (probability is 1 because we've gotten all the successes) and N$N$ less than X$X$ (probability is zero because we have no more trials)
The recursion is really killing the speed of computation, so I'm looking for a closed form or approximation or just a point in the right direction.
Thanks