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

antigravity picture antigravity · Apr 6, 2011 · Viewed 8k times · Source

I need to generate 3 random numbers, the amount of which is equal to 1.

My implementation does not support uniform distribution. :(

Answer

Simen S picture Simen S · Apr 6, 2011

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.