Random number generation from functions

Bengt Richter bokr at oz.net
Mon Nov 29 18:56:11 EST 2004


On Mon, 29 Nov 2004 20:51:50 GMT, "drs" <drs at remove-to-send-mail-ecpsoftware.com> 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,
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



More information about the Python-list mailing list