Skip to content

Instantly share code, notes, and snippets.

View lKingslayer's full-sized avatar
🎯
Focusing

Ray Liu lKingslayer

🎯
Focusing
  • Carnegie Mellon
  • Pittsburgh
View GitHub Profile
@rsnemmen
rsnemmen / randomvariate.py
Last active September 15, 2022 05:46
Rejection method for random number generation / Python
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)