Random number with specific variance in Python

耗尽温柔 提交于 2019-12-01 00:39:36
import math
from random import gauss

my_mean = 0
my_variance = 10

random_numbers = [gauss(my_mean, math.sqrt(my_variance)) for i in range(100)]

This gets you 100 normally-distributed random numbers with mean 0 and variance 10.

Use random.normalvariate (or random.gauss if you don't need thread-safety), and set the sigma argument to the square root of the variance.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!