def alldifferent(k,n):
    '''The probability that k random selections from n possibilities
    are all different.'''
    assert(k<=n)
    nums = xrange(n,n-k,-1)
    dens = itertools.repeat(n)
    fracs = itertools.imap(lambda x,y: float(x)/y, nums,dens)
    return reduce(float.__mul__, fracs)
The probability that k random selections from n possibilities
    are all different.
recipes/Python/578387_Hash_collisiprobability__Birthday/recipe-578387.py