在偏向边界的matlab中生成随机数

Generating random numbers in matlab biased towards the boundaries

我想在 matlab 中生成有偏随机数。让我解释一下,我所说的有偏见。 假设我分别定义了 30 和 10 的上限和下限。 我想生成 N 个偏向边界的随机数,这样数字接近 10 和 30(极端值)的概率比它们位于中间某个位置的概率更大。 我怎样才能做到这一点? 非常感谢任何帮助:)

要为任意分布生成随机数,您必须定义反转 cumulative distribution function。假设您将其命名为 myICDF。获得此功能后,您可以使用 myICDF(rand(n,m)).

生成随机样本
% Upper bound
UB = 30
% Lower bound
LB = 0;
% Range
L = UB-LB;
% Std dev - you may want to relate it to L - maybe use sigma=sqrt(L)
sigma = L/6;
% Number of samples to generate
n = 1000000;
X = sigma*randn(1,n);
% Remove items that are above bounds - not sure if it's what you want.. if not comment the two following lines
X(X<-L) = [];
X(X>L) = [];

% Take values above zero for lower bounds, other values for upper bound
ii = X > 0;
X(ii) = LB + X(ii);
X(~ii) = UB + X(~ii);

% plot histogram
hist(X, 100);

我在这里使用的是正态分布,但显然您可以适应使用其他分布。您也可以更改 sigma。