Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.fr>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Weighted random number generator
Date: Tue, 22 Jul 2008 09:21:03 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 21
Message-ID: <g648pv$drr$1@fred.mathworks.com>
References: <g647ip$2d5$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.fr>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1216718463 14203 172.30.248.35 (22 Jul 2008 09:21:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 22 Jul 2008 09:21:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:480858


"stinkinrich88 Coombez" <stinkinrich88@gmail.com> wrote in
message <g647ip$2d5$1@fred.mathworks.com>...

> 
> 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?
> 

If you want to generate random variable X having pdf 'f'
(f>=0, integral f = 1), then do the following:

X = g(rand)

where g is the inverse of the cumulative integral of f, i.e.,

g(y) is a number such that
y = integral on [-inf,g(y)] f(t) dt

Bruno