I am trying to generate $M$ random numbers which are exponentially distributed and whose sum adds up to $N$ (for simplicity, $N=1$).

I found that the generated numbers are initially exponentially distributed. However, after re-scaling they become uniformly distributed. What is the reason for that? And is there a solution?

Here is the result:

enter image description here

Any suggestions would be greatly appreciated.

P.S. My code written in Matlab:

samples = 10000;
lambda = 1;
X = -log(rand(samples,2))/lambda;
X = X./sum(X,2); % re-scaling
  • 2
    $\begingroup$ Note that sum(X,2) computes the sum of rows. $\endgroup$ – Jean-Claude Arbaut May 25 at 15:36
  • 1
    $\begingroup$ There is no such thing as "random numbers which are exponentially distributed and whose sum adds up to N:" an exponential distribution assigns some probability to arbitrarily large numbers, whereas limiting the sum to $N$ eliminates that possibility. Could you clarify what you actually need to accomplish? $\endgroup$ – whuber May 25 at 21:23

[Answer revised in view of helpful comment from @whuber.]

If you know the exponential rate $\theta,$ then dividing by $M\theta$ will give you a total near $N=1.$ If you don't know $\theta$ and $M$ is sufficiently large that the $\theta$ is well approximated by the reciprocal of the sample mean (a random variable), then you can still come close.

In what follows, I assume $\theta$ is unknown and $M$ is large. Then I adjust by dividing by the sum.

In R:

x = rexp(10000);  y = x/sum(x)
[1] 1

hist(y, prob=T, ylim=c(0, 10000), col="skyblue2")
curve(dexp(x, 1/mean(y)), add=T, col="red", lwd=2, n = 10001)

enter image description here

Even with smaller $M = 100,$ the adjusted sample has sum $1$ and is nearly exponential.

x = rexp(100);  y = x/sum(x)
[1] 1
[1] 97.64598

ks.test(y, "pexp", 100)

        One-sample Kolmogorov-Smirnov test

data:  y
D = 0.084865, p-value = 0.4674
alternative hypothesis: two-sided

The binning is slightly inconsistent between the two histograms below because $Y = X/97.646,$ not $X/100.$

enter image description here

  • 1
    $\begingroup$ This answer is an illusion owing to the large sample size. Try it with, say, a sample of 3 rather than 10,000. You will have to repeat your experiment a few times, but it will quickly become apparent that the distribution you create is far from exponential. $\endgroup$ – whuber May 25 at 21:22
  • 1
    $\begingroup$ Sorry and thanks. Somehow I was focused on approximate results and M large. Accordingly, I made changes to my Answer. $\endgroup$ – BruceET May 25 at 23:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.