Random number generation from functions

Robert Kern rkern at ucsd.edu
Tue Nov 30 03:04:21 EST 2004


drs wrote:
> Is there any way to generate random numbers based on arbitrary real valued
> functions? I am looking for something like random.gauss() but with natural
> log and exponential functions.

scipy[1] has a large collection of "standard" univariate pdfs, including 
normal, exponential, gamma, and the like.

One cannot generate random numbers from arbitrary real valued functions 
because a function needs to satisfy certain restrictions to be a pdf. 
For example, you cannot generate random numbers "with a log function", 
unless you restrict the domain and renormalize.

Generating random numbers from an arbitrary pdf is possible, but tricky. 
I encourage you to search the literature for "monte carlo sampling."

[1] http://www.scipy.org

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter



More information about the Python-list mailing list