How od i generate random numbers whose sum is constant?

I want 100 random numbers bu their sum should be same.

2 comentarios

You want to generate 100 random numbers several times, I guess ? Because if you generate 100 random numbers once, there is only one sum.
yes, I want to generate several times

Iniciar sesión para comentar.

 Respuesta aceptada

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:

Categorías

Más información sobre Random Number Generation en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 9 de Sept. de 2022

Comentada:

el 9 de Sept. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by