How od i generate random numbers whose sum is constant?

조회 수: 3 (최근 30일)
BHUKYA VENKATESH
BHUKYA VENKATESH 2022년 9월 9일
댓글: BHUKYA VENKATESH 2022년 9월 9일
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.
BHUKYA VENKATESH
BHUKYA VENKATESH 2022년 9월 9일
yes, I want to generate several times

댓글을 달려면 로그인하십시오.

채택된 답변

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