Path: news.mathworks.com!not-for-mail
From: "John D'Errico" <woodchips@rochester.rr.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Weighted random number generator
Date: Tue, 22 Jul 2008 09:53:01 +0000 (UTC)
Organization: John D'Errico (1-3LEW5R)
Lines: 30
Message-ID: <g64alt$1kr$1@fred.mathworks.com>
References: <g647ip$2d5$1@fred.mathworks.com>
Reply-To: "John D'Errico" <woodchips@rochester.rr.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1216720381 1691 172.30.248.38 (22 Jul 2008 09:53:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 22 Jul 2008 09:53:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869215
Xref: news.mathworks.com comp.soft-sys.matlab:480865


"stinkinrich88 Coombez" <stinkinrich88@gmail.com> wrote in message 
<g647ip$2d5$1@fred.mathworks.com>...
> Hello,
> 
> I would like a function similar to the rnd function but I
> want the generated numbers to be weighted, i.e. I would like
> the function to be more likely to give me a higher number
> than a lower number and I would like to be able to specify
> this probability. 
> 
> For example, the betarnd function almost does what I want. I
> can make a sloping probability distribution with it. The
> only trouble is the probability distribution bulges slightly
> in the middle and I want it to be straight. 
> 
> Is there any function I can use to do this? Or a function
> that gives me random numbers (between 0-1) using a formula
> that I specify?
> 
> Thanks!

While you can indeed generate your own
random generator for a linear pdf, it is
also trivial to use the stats toolbox and the
beta distribution. You just need to choose
the proper set of parameters.

ezplot(@(x) betapdf(x,2,1),[0 1])

John