By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
 424,846 Members | 2,107 Online + Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,846 IT Pros & Developers. It's quick & easy.

# Random number generation from functions

 P: n/a 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. thanks, -d Jul 18 '05 #1
Share this Question
5 Replies

 P: n/a On Mon, 29 Nov 2004 20:51:50 GMT, "drs" wrote: Is there any way to generate random numbers based on arbitrary real valuedfunctions? I am looking for something like random.gauss() but with naturallog and exponential functions.thanks, Don't know what you mean. This kind of thing? (the 1-random... is to make the random numbers in (0,1] instead of [0,1)) import random import math math.log(1.0-random.uniform(0,1)) -0.90030288455841156 math.log(1.0-random.uniform(0,1)) -0.261249141864835 math.log(1.0-random.uniform(0,1)) -0.99694366818547997 Regards, Bengt Richter Jul 18 '05 #2

 P: n/a 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. thanks, -d numarray has a random package which provides a number of functions, including: normal( mean, stddev, shape=[]) That may serve your need. Colin W. Jul 18 '05 #3

 P: n/a 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. thanks, -d I remember for having used it on a gaussian generator that you can do that very easily by yourself: - you generate a random real number in the range [0 .. 1], - then you apply an inverse probability density function (e.g. inverse gaussian pdf : http://www.itl.nist.gov/div898/softw...ar/rigpdf.htm), and you have then your random number following the specified law (here gaussian). Jul 18 '05 #4

 P: n/a 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 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."  http://www.scipy.org -- Robert Kern rk***@ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter Jul 18 '05 #5

 P: n/a On Mon, 29 Nov 2004 20:51:50 GMT, "drs" wrote: Is there any way to generate random numbers based on arbitrary real valuedfunctions? I am looking for something like random.gauss() but with naturallog and exponential functions. Try with CRNG, it may have what you need, or be able to adapt it to what you want. http://www.sbc.su.se/~per/crng/ Jul 18 '05 #6

### This discussion thread is closed

Replies have been disabled for this discussion. 