How od i generate random numbers whose sum is constant?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
BHUKYA VENKATESH
am 9 Sep. 2022
Kommentiert: BHUKYA VENKATESH
am 9 Sep. 2022
I want 100 random numbers bu their sum should be same.
2 Kommentare
Torsten
am 9 Sep. 2022
You want to generate 100 random numbers several times, I guess ? Because if you generate 100 random numbers once, there is only one sum.
Akzeptierte Antwort
Bruno Luong
am 9 Sep. 2022
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 Kommentare
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Random Number Generation finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!