0% found this document useful (0 votes)
59 views

Generate Random Numbers With Custom PDF

Uploaded by

Arun Nair
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

Generate Random Numbers With Custom PDF

Uploaded by

Arun Nair
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

MATLAB Answers

Generate random numbers with custom PDF


 Follow 149 views (last 30 days)

Michael

on 11 Jun 2012  Vote 2

Edited: Walter Roberson




on 10 Jun 2018

Hi, as it may become clear I'm fairly weak on probability distributions

I want to generate a set of random numbers between 0 and 1, but able to alter the weighting of these
numbers. For example if I could input some sort of "bias" parameter which determines the extent to
which the numbers tend to be closer to 0 than to 1, for example.

I don't know which of MATLAB's many distributions I should use. So far I've been using the uniform
distribution and taking it to the power N, but N=0.5 seems to give an entirely different PDF shape (in
favour of numbers close to 1) than the intended opposite bias, N=2 (in favour of numbers close to 0).
Squaring it seems to favour small numbers far more than sqrt-ing seems to favour large numbers, so
I've rejected this approach as unfair.

Is there a common distribution for this? Numbers have to be between 0 and 1 and I want to take control
of how close they are, on average, to either.

Thanks Mike

   0 Comments
Sign in to comment.

Sign in to answer this question.


Answers (4)

Image Analyst

  Vote 3  Link
on 10 May 2013

Tons of distributions are given here:


http://www.mathworks.com/matlabcentral/fileexchange/7309-randraw

In general, you basically compute the CDF of your PDF function and invert it. Go here for a
generally applicable explanation of how to do it:
http://en.wikipedia.org/wiki/Inverse_transform_sampling

   1 Comment
Martins Ezuma
on 10 Jun 2018 
Thanks

Sign in to comment.

Pantelis Sopasakis
on 10 May 2013  Vote 1  Link

You may consider using this PDFSampler. I believe, it does exactly what you need. You just
need to specify how you want your samples to be distributed, e.g. you may provide their
histogram.

   0 Comments
Sign in to comment.

Tom Lane

on 11 Jun 2012  Vote 0  Link

If you have the Statistics Toolbox, then take a look at the beta distribution. Use it with disttool
to see how the parameters affect the distribution, randtool to see what a random sample from
this distribution looks like, and betarnd to generate your own sample from the command line
or inside a function.

   0 Comments
Sign in to comment.

Ka Mirul

on 14 Nov 2017  Vote 0  Link

Edited: Walter Roberson




on 10 Jun 2018

I have create a video about generating random number in MATLAB


https://www.youtube.com/watch?v=MyH3-ONYL_k

Hope that will help you

   0 Comments
Sign in to comment.

Sign in to answer this question.

ANNOUNCEMENT
×
New User Levels and Badges Introduced to MATLAB Answers!
Several major updates have been introduced to Answers’ reputation system! The updates...

See Also
MATLAB Answers
Random number generator based on probability distribution
1 Answer
Probability distribution and statistical tool
0 Answers

How to generate random values from tlocationscale distributions ?


0 Answers

Entire Website
Random Number
Products

PDFsampler
File Exchange

Supported Distributions
Documentation

Categories
MATLAB

Mathematics

Random Number Generation

Tags
rand probability pdf distribution
Poll

What type of music do you listen to while coding? Share your playlists in the
comments!

Ambient | Atmospheric | Nature

Classical | Jazz | Musicals

Electronic | Dubstep | House | VGM

Lo-fi | Chill | Coffee House

Rock | Metal | Pop | Punk | Hip Hop

Other | Podcasts | Nothing

710 votes
8 comments
350 views

Vote

mathworks.com
© 1994-2022 The MathWorks, Inc. MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See mathworks.com/trademarks for a list of additional
trademarks. Other product or brand names may be trademarks or registered trademarks of their respective holders.

Join the conversation

You might also like