Skip to content

Instantly share code, notes, and snippets.

@walterreade
Created January 31, 2016 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walterreade/b8eea917a5066a45c6b9 to your computer and use it in GitHub Desktop.
Save walterreade/b8eea917a5066a45c6b9 to your computer and use it in GitHub Desktop.
from scipy import exp, log
from scipy.special import gammaln
def prob_unique(N, r):
""" If you have a set of N things to choose from, and take r samples,
the probability that all r samples are unique.
http://www.johndcook.com/blog/2016/01/30/general-birthday-problem
"""
return exp( gammaln(N+1) - gammaln(N-r+1) - r*log(N) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment