Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
random numbers

Subject: random numbers

From: Wendy

Date: 28 May, 2010 00:52:06

Message: 1 of 4

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

Subject: random numbers

From: Walter Roberson

Date: 28 May, 2010 00:59:26

Message: 2 of 4

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".

Subject: random numbers

From: Roger Stafford

Date: 28 May, 2010 01:59:05

Message: 3 of 4

"Wendy " <wlq121@gmail.com> wrote in message <htn43m$3t0$1@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

Subject: random numbers

From: Roger Stafford

Date: 28 May, 2010 02:08:04

Message: 4 of 4

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <htn818$6kj$1@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

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us