This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def binomial(n, k): | |
""" | |
A fast way to calculate binomial coefficients by Andrew Dalke. | |
See http://stackoverflow.com/questions/3025162/statistics-combinations-in-python | |
""" | |
if 0 <= k <= n: | |
ntok = 1 | |
ktok = 1 | |
for t in xrange(1, min(k, n - k) + 1): | |
ntok *= n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def randomvariate(pdf,n=1000,xmin=0,xmax=1): | |
""" | |
Rejection method for random number generation | |
=============================================== | |
Uses the rejection method for generating random numbers derived from an arbitrary | |
probability distribution. For reference, see Bevington's book, page 84. Based on | |
rejection*.py. | |
Usage: | |
>>> randomvariate(P,N,xmin,xmax) |