Reputation: 1182
I have a repeated binomial test (p = probability of success, n = no of trials). I want to randomly generate the number of successes.
I could just generate n random numbers, but that is too inefficient. i.e. not like this:
def successes(p, n):
count = 0
for i in xrange(n):
if random.random() < p:
count += 1
return count
I want this to be an exact sample (not a normal or other approximation) as this is going to be used repeatedly for highly skewed distributions.
I feel that this could be done using the density functions etc ( http://en.wikipedia.org/wiki/Binomial_distribution#Probability_mass_function ) but I can't quite wrap my head around it.
Upvotes: 0
Views: 2728