Q:

How to generate three random numbers, whose sum is 1?

I need to generate 3 random numbers, the amount of which is equal to 1.
My implementation does not support uniform distribution. :(

A:

Just get 3 random numbers and then calculate a factor which is 1 / [sum of your numbers]. Finally multiply each of the random numbers with that factor. The sum will be 1.

A:

This is actually a tricky question. First of all:
 Daren's solution is not uniform because it does not support having two numbers > 1/3.
 Simen's solution is not uniform assuming the "pick a random number" draws from a uniform distribution, but this is a bit more subtle. It is at least symmetric between the variables (i.e. the probability of [a, b, c] is the same as that of any permutation of that), but it heavily favors solutions closer to (1/3, 1/3, 1/3). Think about it this way by looking at extreme cases:
(1/3, 1/3, 1/3) could have come from any (a, a, a), where a ranges from 0 through 1.
(1, 0, 0), an equally valid triple, must come from (1, 0, 0).
One solution: The set of positive numbers that add to 1 form a n equilateral triangle in three-space, with coordinates (1,0,0), (0,1,0), (0,0,1). Extend that to a parallelogram -- e.g. by adding a point (1,1,-1) as the fourth point. This double's the area -- map the second area to the first, so that it suffices to pick a random point in this parallelogram.
The parallelogram can be sampled uniformly via (0,0,1) + A(1,0,-1) + B (0,1,-1), where A and B range uniformly from 0 to 1.
-A

A:

Generate two random numbers between 0 and 1.
Divide those each by 3.
The third is the difference of 1 and the two random thirds:
void Main()
{
    Random r = new Random();
    double d1 = r.NextDouble() / 3.0;
    double d2 = r.NextDouble() / 3.0;
    double d3 = 1.0 - d1 - d2;
    System.Console.WriteLine(d1);
    System.Console.WriteLine(d2);
    System.Console.WriteLine(d3);
    System.Console.WriteLine(d1 + d2 + d3);
}

this outputs the following in LINQPad:
0.0514050276878934
0.156857372489847
0.79173759982226
1

