We have 4 balls marked with numbers 1,2,3,4. From these we draw 2. What is the probability that these 2 balls are marked 1 and 2?
We can count the number of ways to draw 2 balls:
The draw (1,2) is one of these, so the probability is 1/6. This can also be calculated using the binomial coefficient:
The probability of a random draw is:
where n is the set of distinct elements to draw from and k is the number of elements drawn.
Our example, the probability af drawing the balls 1 and 2 from the 4 balls:
Another example could be the probability of drawing a royal flush in the game of poker. There are 4 different royal flushes and 52 cards. Then we have:
This Python program demonstrates calculation using the binomial function:
def fac(x):
if x==0: return 1
else : return x*fac(x-1)
def bin(n, k):
return fac(n) / (fac(n-k)*fac(k))
print " [ 52 ]"
print "The probability of a royal straight flush is 1 / [ 4 ] = %.4e" % (1. / bin(52,4))