Re-scaling of exponentially distributed random numbers 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:

Any suggestions would be greatly appreciated.
P.S. My code written in Matlab:
subplot(121)
samples = 10000;
lambda = 1;
X = -log(rand(samples,2))/lambda;
hist(X(:,1),100)
subplot(122)
X = X./sum(X,2); % re-scaling
hist(X(:,1),100)

 A: [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:
set.seed(525)
x = rexp(10000);  y = x/sum(x)
sum(y)
[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)


Even with smaller $M = 100,$ the adjusted sample has sum $1$ and is nearly exponential.
set.seed(1234)
x = rexp(100);  y = x/sum(x)
sum(y)
[1] 1
sum(x)
[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.$

