I have this problem: I'm trying to sample the relation $$ \sum_{i=1}^N x_i = 1 $$ in the domain where $x_i>0\ \forall i$. Right now I'm just extracting $N$ random numbers $u_i$ from a uniform distribution $[0,1]$ and then I transform them into $x_i$ by using $$ x_i = \frac{u_i}{\sum_{i=1}^N{u_i}}. $$
This is correct but requires me three $u_i$ to have a sample of the relation.
If $N=2$, then the relation simplify into $x_1 + x_2 = 1$ and I can easily extract one $u_1 = x_1$ and evaluate the other as $x_2 = 1 - x_1$, therefore using only one extraction. But if I do the same with $N=3$, I can have $u_1 = 0.8$, $u_2 = 0.7$ and I can't just use the first relation to evaluate the $x_i$ and I cannot combine it with the second one, since I don't know the $\sum u_i$.
How can I sample the $x_i$ that satisfies the first relation while only picking $N-1$ values from a random distribution (preferably the uniform one)? And what kind of mathematical problem is this?
PS I'm not a mathematician and this is my first question here. I've searched for an answer but I think that I haven't already well defined the problem so I don't really know what to search. I feel the solution might be close to this but I can't figure out how. So I would appreciate any help on better defining the problem from a mathematical point of view, as well on finding its solution (of course xD)
PS2 also a help to better choose the tags and the title would be appreciated
Mathematically, you are trying to uniformly sample points on a simplex, which in turn is also equivalent to sampling points from a Dirichlet distribution and then normalizing.
Here's how to see all this: take the unit interval and pick uniformly at random and independently $N-1$ points. These points partition the unit line into segments, so take your $x_i$ to equal the lengths of the segments. Basically, to implement this, you draw the $N-1$ points at random and then you sort them in increasing order, which gives you a kind of Beta distribution.
If you need to program this, here's one efficient way of doing it without sorting:
1) Generate $N$ independent points $E_i$ from a an exponential distribution by drawing $U_i$ from a uniform distribution on $[0,1]$ and then compute the negative logorithm: $E_i:=-\log(U_i)$.
2) Sum all samples to get $S:=\sum_{i=1}^{N}E_i$.
3) The vector $x:=(x_1,\ldots,x_{N})$, where $x_i=E_i/S$ is uniformly distributed in your space.