Thread Subject: Between Random number

Subject: Between Random number

From: Subrat Swain

Date: 23 Nov, 2008 04:45:02

Message: 1 of 6

Hi all,
I would like to determine a random number between two defined numbers; example a random number between 5 and 10.
For example in MS excel I used randbetween(5,10) and it returns a random number between 5 and 10. I would like to perform the same operation in MATLAB but couldnot find the syntax.
I am very new to MATLAB.
I would appreciate if any help.

Regards,
Subrat.

Subject: Between Random number

From: Husam Aldahiyat

Date: 23 Nov, 2008 05:07:01

Message: 2 of 6

>> rand*5+5;

Subject: Between Random number

From: Walter Roberson

Date: 23 Nov, 2008 05:14:01

Message: 3 of 6

Husam Aldahiyat wrote:
>>> rand*5+5;

Note that that will return a random number that is -strictly- between 5 and 10
and will never be -exactly- 5 or -exactly- 10.

Also note that the number so calculated will have a uniform random distribution,
(to within one part in 2^53).

--
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?

Subject: Between Random number

From: Subrat Swain

Date: 23 Nov, 2008 05:16:02

Message: 4 of 6

"Husam Aldahiyat" <numandina@gmail.com> wrote in message <ggaodl$iol$1@fred.mathworks.com>...
> >> rand*5+5;

Thank you so much. It works.

Subject: Between Random number

From: Steven Lord

Date: 24 Nov, 2008 08:59:33

Message: 5 of 6


"Subrat Swain" <swain.subrat01@gmail.com> wrote in message
news:ggan4e$2dp$1@fred.mathworks.com...
> Hi all,
> I would like to determine a random number between two defined numbers;
> example a random number between 5 and 10.
> For example in MS excel I used randbetween(5,10) and it returns a random
> number between 5 and 10. I would like to perform the same operation in
> MATLAB but couldnot find the syntax.
> I am very new to MATLAB.
> I would appreciate if any help.

Since the help for RANDBETWEEN says that it generates random integers, if
you're using release R2008b, use the new RANDI function.

Alternately, shift and scale the output of RAND to the desired range, then
use FIX, FLOOR, CEIL, or ROUND to round the shifted and scaled output to
integers.

--
Steve Lord
slord@mathworks.com

Subject: Between Random number

From: ImageAnalyst

Date: 24 Nov, 2008 13:53:28

Message: 6 of 6

On Nov 24, 3:59=A0am, "Steven Lord" <sl...@mathworks.com> wrote:
> "Subrat Swain" <swain.subra...@gmail.com> wrote in message
>
> news:ggan4e$2dp$1@fred.mathworks.com...
>
> > Hi all,
> > I would like to determine a random number between two defined numbers;
> > example a random number between 5 and 10.
> > For example in MS excel I used randbetween(5,10) and it returns a rando=
m
> > number between 5 and 10. I would like to perform the same operation in
> > MATLAB but couldnot find the syntax.
> > I am very new to MATLAB.
> > I would appreciate if any help.
>
> Since the help for RANDBETWEEN says that it generates random integers, if
> you're using release R2008b, use the new RANDI function.
>
> Alternately, shift and scale the output of RAND to the desired range, the=
n
> use FIX, FLOOR, CEIL, or ROUND to round the shifted and scaled output to
> integers.
>
> --
> Steve Lord
> sl...@mathworks.com

-------------------------------------
Steve:
That randi function looks very nice. I just tried it out. It's sure
to become useful. (Don't know why it took so long, but thanks for
finally adding it.)

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Contact us at files@mathworks.com