From: "John D'Errico" <>
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$>
References: <g647ip$2d5$>
Reply-To: "John D'Errico" <>
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: 1216720381 1691 (22 Jul 2008 09:53:01 GMT)
NNTP-Posting-Date: Tue, 22 Jul 2008 09:53:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869215
Xref: comp.soft-sys.matlab:480865

"stinkinrich88 Coombez" <> wrote in message 
> 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])