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!