Thread Subject:
Random Number Generation

Subject: Random Number Generation

From: Corey Adrian

Date: 12 Jul, 2010 16:59:04

Message: 1 of 5

I am trying to create a random number array given a minimum, maximum, and mean value. Is there any way to do this?

Thanks,
Corey

Subject: Random Number Generation

From: Steven Lord

Date: 12 Jul, 2010 17:11:01

Message: 2 of 5


"Corey Adrian" <uryguitarist777@yahoo.com> wrote in message
news:i1fhko$rsc$1@fred.mathworks.com...
>I am trying to create a random number array given a minimum, maximum, and
>mean value. Is there any way to do this?

Sure, just write a function that errors if the specified mean value is less
than the specified minimum or greater than the specified maximum value and
otherwise returns your mean value.

http://dilbert.com/strips/comic/2001-10-25/

If you want your numbers distributed differently in the interval between
your minimum and maximum than "centered at the mean value", you need to
provide a description of your desired distribution.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Random Number Generation

From: Roger Stafford

Date: 12 Jul, 2010 21:36:04

Message: 3 of 5

"Corey Adrian" <uryguitarist777@yahoo.com> wrote in message <i1fhko$rsc$1@fred.mathworks.com>...
> I am trying to create a random number array given a minimum, maximum, and mean value. Is there any way to do this?
>
> Thanks,
> Corey
- - - - - - - -
  How about using the beta distribution? Let a = minimum, b = maximum, and c = mean. Of course, it is assumed that a < c < b here. Then do:

 x = a+(b-a)*betarnd((c-a)/(b-a),(b-c)*(b-a),m,n);

to get an m by n array x of such random numbers.

  You can multiply the first two arguments of betarnd by any common factor to change the distribution's variance at your pleasure without affecting the mean. By making this factor very large you can approach Steven's interesting suggestion.

Roger Stafford

Subject: Random Number Generation

From: Roger Stafford

Date: 12 Jul, 2010 21:40:16

Message: 4 of 5

  Oops! I meant

 x = a+(b-a)*betarnd((c-a)/(b-a),(b-c)/(b-a),m,n);

Roger Stafford

Subject: Random Number Generation

From: Corey Adrian

Date: 12 Jul, 2010 22:30:11

Message: 5 of 5

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i1g240$rho$1@fred.mathworks.com>...
> Oops! I meant
>
> x = a+(b-a)*betarnd((c-a)/(b-a),(b-c)/(b-a),m,n);
>
> Roger Stafford

Thanks Roger that is exactly what I needed!

Corey Adrian

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