If I'm doing a simulation with $n$ trials, each with probability $p$, a quick way to select the successful trials is to choose a binomially distributed random number. Then randomly choose that many trials to be successful.
But what if the probabilities are distinct? I want to - as efficiently as possible - do a simulation in which I select the events that are successful. So I'd like to avoid generating a random number for each trial.
To make things specific, let's assume I've got $p_1$, ... , $p_{20}$ with each probability being some small number, say no bigger than $0.05$. I'd like to generate the successes without 20 coin flips.
Any suggestions? I know one way to do it if I order the probabilities and use a rejection sampling approach, but it would be great if I could avoid the cost of ordering them.
Here's a suggestion:
Lets say you have $n$ trials ($T_i$), where $p_i = P(T_i=1), q_i=1-p_i$. Then there are $2^n$ combinations of successful trials (e.g., $(1,0,0,1)$ is one such combination if $n=4$).
After doing this, you will have a discrete probability distribution over $i\in I:\mathbf{P}(i)$
Now, to simulate successes, you just do the following:
So, I've substituted some up-front computation to reduce your problem to a single-variable simulation.