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$>
References: <g647ip$2d5$> <g64alt$1kr$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: 1216725123 17799 (22 Jul 2008 11:12:03 GMT)
NNTP-Posting-Date: Tue, 22 Jul 2008 11:12:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1446565
Xref: comp.soft-sys.matlab:480892

"John D'Errico" <> wrote in
message <g64alt$1kr$>...
> "stinkinrich88 Coombez" <> wrote in
> <g647ip$2d5$>...
> > 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?