python random.lognormvariate(),对数正态分布随机数

lognormvariate()函数

python中random模块的lognormvariate()函数,可以用来获取对数正态分布的随机数。


语法

random.lognormvariate(mu, sigma)

下面这个模块中的内容来自python中部分源码对lognormvariate()方法的介绍:

Log normal distribution.
    
    If you take the natural logarithm of this distribution, you'll get a
    normal distribution with mean mu and standard deviation sigma.
    mu can have any value, and sigma must be greater than zero.

参数

参数描述
mu必须参数,如上面源码“mean mu”,即表示平均数
sigma必须参数,如上面源码,“standard deviation sigma”,表示标准差

random.lognormvariate()实例代码

>>> import random
>>> random.lognormvariate(5,0.2)
105.70950830130332

上面实例中获取的是平均数为5,标准差为0.2的对数正态分布随机数。



全栈后端 / Python库 :









Copyright © 2022-2024 笨鸟工具 x1y1z1.com All Rights Reserved.