From: Wendy on
Hi all,

I want to generate 30 random numbers that are between 0 and 1, and these 30 numbers have to add up to 1. Does anyone know how to generate random numbers that add up to a certain value?

Thank you in advance,
Wendy
From: Walter Roberson on
Wendy wrote:

> I want to generate 30 random numbers that are between 0 and 1, and these
> 30 numbers have to add up to 1. Does anyone know how to generate random
> numbers that add up to a certain value?

See yesterday's thread (active today as well), "random values".
From: Roger Stafford on
"Wendy " <wlq121(a)gmail.com> wrote in message <htn43m$3t0$1(a)fred.mathworks.com>...
> Hi all,
>
> I want to generate 30 random numbers that are between 0 and 1, and these 30 numbers have to add up to 1. Does anyone know how to generate random numbers that add up to a certain value?
>
> Thank you in advance,
> Wendy

This is straight out of Wikipedia.

r = diff([0;sort(rand(30,1));1]);

Roger Stafford
From: Roger Stafford on
"Roger Stafford" <ellieandrogerxyzzy(a)mindspring.com.invalid> wrote in message <htn818$6kj$1(a)fred.mathworks.com>...
> .......
> r = diff([0;sort(rand(30,1));1]);
> ......

Sorry. I meant to write

r = diff([0;sort(rand(29,1));1]);

Roger Stafford