Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Weighted random number generator
Date: Tue, 22 Jul 2008 11:12:03 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 44
Message-ID: <g64fa3$hc7$1@fred.mathworks.com>
References: <g647ip$2d5$1@fred.mathworks.com> <g64alt$1kr$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1216725123 17799 172.30.248.37 (22 Jul 2008 11:12:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 22 Jul 2008 11:12:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1446565
Xref: news.mathworks.com comp.soft-sys.matlab:480892


"John D'Errico" <woodchips@rochester.rr.com> wrote in
message <g64alt$1kr$1@fred.mathworks.com>...
> "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

Thanks for your responses, everyone. I'm just getting my
head around them!

John, your solution looks great, the only trouble is I need
to be able to adjust the steepness of the slope. I have
tried adjusting the parameters for betapdf but I end up with
a curve. Is there a way I can adjust the steepness of the
slop while keeping it flat? 

thanks!