python random.expovariate()方法,指数分布随机数
random.expovariate()方法
python的random模块中的expovariate()方法,可以用来返回一个指数分布的随机数。
语法
expovariate( lambd )
expovariate()的python源码中的介绍:
expovariate(lambd) method of random.Random instance
Exponential distribution.
lambd is 1.0 divided by the desired mean. It should be
nonzero. (The parameter would be called "lambda", but that is
a reserved word in Python.) Returned values range from 0 to
positive infinity if lambd is positive, and from negative
infinity to 0 if lambd is negative.
参数
random.expovariate()方法接收一个nonzero非零的参数,而且lambd是 1.0 除以所需的平均值。
指数分布
在概率理论和统计学中,负指数分布(也称为指数分布)是描述泊松过程中的事件之间的时间的概率分布,即事件以恒定平均速率连续且独立地发生的过程。 (来源百度百科)
>>> import random
>>> random.expovariate(1)
1.4659067155532202
>>> random.expovariate(10)
0.21374004438702512
>>> random.expovariate(100)
0.01704000634559867
>>> random.expovariate(1000)
0.0012355619830804502