File Exchange

image thumbnail

Random numbers from a user defined distribution

version (2.15 KB) by Adam Nieslony
creturns the matrix of random numbers from user defined probability density distribution.


Updated 02 Dec 2009

View License

RANDPDF returns the matrix of random numbers from probability density distribution defined in p and px. p are the density (the y axis) and px are the value (the x axis) of the pdf. p and px must be of the same length. dim define the output matrix dimensions, for example dim=[100 3] define the 100x3 two dimensional matrix with 300 random numbers.

REMEMBER: This is not a really random number generator but only some kind of transformation of uniformly distributed pseudorandom numbers to desired pdf!

Cite As

Adam Nieslony (2021). Random numbers from a user defined distribution (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (16)

Max Endo Kokubun

Derrick Gao

thank you !!!!!!!!!!!!!!!!!!!

Suropriya Saha

Xiaochu Wang

Thank you for your work!

Dawid Augustyn

Shubham Garg

Pan Tang


Can you please modify code to suit for multivariate distributions


Way faster than my home-brew. Thanks!

Rebecca Kelly

Fei Ren

Work well for my 1D pdf.

sawon pratiher

moshe lindner

simple, but do the job!

Jean-Luc Dellis

I wanted to do it, you already did it... perfectly. TY.


MATLAB Release Compatibility
Created with R14SP3
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired: randpdf2(x, y, p, m)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!