How od i generate random numbers whose sum is constant?
조회 수: 3 (최근 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!