Matlab: Generate Random Numbers With A Given Distribution
Matlab: Generate Random Numbers With A Given Distribution
com/post-44/generate-random-numbers-with-a-given-distribution
matlabtricks.com
0 5 O c t o b e r, 2 0 1 4
A great article written by John S. Denker explains a method of generating random numbers with arbitrary distribution.
This post is based on his work, and shows a simple MATLAB implementation.
0.12
0.1
0.08
p(x)
0.06
0.04
0.02
0
0 2 4 6 8 10 12
We have an R range and we can pick any x random value between Rmin = 1 and Rmax = 11. The probability of all
possible x values equals to 0.1.
By having a closer look at the p(x) function, we realize, that the area under it equals to 1. That means that if we pick a
random x value from the range (1, 11), the probability, that the value falls between 1 and 11 is exactly 1. Similarly, the
area under p(x) for a sub-range of R equals to the probability of x falling into that sub-range.
For example the probability of x falling into the (1, 6) sub-range equals to 0.1 * (6 - 1) = 0.5. Because the (1, 6)
sub-range covers the half of the possible outcomes, that is true.
Now take the integral of p(x) and have a look at the resulting P(x) function:
1 of 5 29/06/17 16:45
http://matlabtricks.com/post-44/generate-random-numbers-with-a-given-distribution
2 of 5 29/06/17 16:45
http://matlabtricks.com/post-44/generate-random-numbers-with-a-given-distribution
3 of 5 29/06/17 16:45
http://matlabtricks.com/post-44/generate-random-numbers-with-a-given-distribution
4 of 5 29/06/17 16:45
http://matlabtricks.com/post-44/generate-random-numbers-with-a-given-distribution
5 of 5 29/06/17 16:45