How od i generate random numbers whose sum is constant?

2 次查看(过去 30 天)
I want 100 random numbers bu their sum should be same.
  2 个评论
Torsten
Torsten 2022-9-9
You want to generate 100 random numbers several times, I guess ? Because if you generate 100 random numbers once, there is only one sum.

请先登录,再进行评论。

采纳的回答

Bruno Luong
Bruno Luong 2022-9-9
If the numbers are supposed to be >= 0 with precribed sum, a simple method is
n = 100;
s = 10;
Y = -log(rand(1,n));
X = s * Y ./ sum(Y,2)
sum(X)
The justification of log is from the ubiased conditioning probability that I explain here:

更多回答(1 个)

Bruno Luong
Bruno Luong 2022-9-9
编辑:Bruno Luong 2022-9-9

类别

Help CenterFile Exchange 中查找有关 Random Number Generation 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by