```Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Random Number Generation
Date: Thu, 27 Jun 2013 05:23:06 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 22
Message-ID: <kqgi7q\$jpl\$1@newscl01ah.mathworks.com>
References: <i1fhko\$rsc\$1@fred.mathworks.com> <i1g240\$rho\$1@fred.mathworks.com> <i1g51j\$5g4\$1@fred.mathworks.com> <kqf3he\$rv4\$1@newscl01ah.mathworks.com>
NNTP-Posting-Host: www-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1372310586 20277 172.30.248.47 (27 Jun 2013 05:23:06 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 27 Jun 2013 05:23:06 +0000 (UTC)
Xref: news.mathworks.com comp.soft-sys.matlab:798406

"taffi" wrote in message <kqf3he\$rv4\$1@newscl01ah.mathworks.com>...
> i need to use a std deviation as well. i have a max, min, mean and also a std value. How can i get random numbers of beta distribution wid a certain standard deviation.
-------------------
As I said back in 2010. "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."  This can be done as follows.  Call a = max, b = min, m = mean, and s = std.  Then you can generate the desired beta distribution with

f = ((b-m)*(m-a)-s^2)/s^2;
x = a+(b-a)*betarnd((m-a)/(b-a)*f,(b-m)/(b-a)*f,M,N);

As you can see, that "common factor" is the above 'f'.  Note that both m and s are constrained by the inequalities

a < m < b
0 < s < sqrt((b-m)*(m-a))

so the choice of s isn't fully "at your pleasure".

You can consult the website

http://en.wikipedia.org/wiki/Beta_distribution

to check that the above formula results in the desired mean and standard deviation.

Roger Stafford
```