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
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
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:
0 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Random Number Generation 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!