How od i generate random numbers whose sum is constant?

2 vues (au cours des 30 derniers jours)
BHUKYA VENKATESH
BHUKYA VENKATESH le 9 Sep 2022
I want 100 random numbers bu their sum should be same.
  2 commentaires
Torsten
Torsten le 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.
BHUKYA VENKATESH
BHUKYA VENKATESH le 9 Sep 2022
yes, I want to generate several times

Connectez-vous pour commenter.

Réponse acceptée

Bruno Luong
Bruno Luong le 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:

Plus de réponses (1)

Bruno Luong
Bruno Luong le 9 Sep 2022
Modifié(e) : Bruno Luong le 9 Sep 2022

Catégories

En savoir plus sur Random Number Generation dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by