且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从具有特定均值和方差的正态分布中生成随机数?

更新时间:2023-02-10 12:13:50

A standard正态分布 已经具有均值0和方差1.

A standard normal distribution already has mean 0 and variance 1.

如果您要更改均值,只需转换"分布即可,即,将平均值添加到每个生成的数字中.同样,如果您要更改方差,只需缩放"分布,即将所有数字乘以sqrt(v).例如,

If you want to change the mean, just "translate" the distribution, i.e., add your mean value to each generated number. Similarly, if you want to change the variance, just "scale" the distribution, i.e., multiply all your numbers by sqrt(v). For example,

v = 1.5; % variance
sigma = sqrt(v); % standard deviation
mu = 2; % mean
n = 1000
X = sigma .* randn(n, 1) + mu;
stats = [mean(X) std(X) var(X)]

请参阅以下文章:

https://ch.mathworks.com/help/matlab/math/random-numbers-with-specific-mean-and-variance.html

了解更多信息.