Simulate the number of times a random condition is met in n attempts

17 Views Asked by At

If every time a condition is evaluated, there is exactly an x chance of it succeeding (RAND() < x), is there any way to simulate this formula n times, in order to get the number of successes?

I'm not asking about an average, although, if the formula worked as expected, higher values of nwould have results getting closer to the average.

Bit of background info:

I'm addressing this from a programming perspective, so the simple (yet expensive) solution would be to iteration i = 0 to n, evaluate RAND() < x, and count the number of successes.

However, I'll be dealing with quite varied values of n, from very low, to quite high, and performance will be quite critical. Evaluating RAND() 1,000,000 times just to simulate this is quite unideal.

1

There are 1 best solutions below

0
On

You don't need to simulate. You can compute the probability of $k$ successes in $n$ trials using the binomial formula or the normal approximation (for large $n$).