How to generate a random number with a specific probability density function?
java, probability-theory, random
Solution
Rayleigh distribution is a special case of the Weibull distribution. If you google around, there are lots of Weibull generators written in Java, for example:
- http://commons.apache.org/math/apidocs/org/apache/commons/math3/distribution/WeibullDistribution.html
- http://www.iro.umontreal.ca/~simardr/ssj/doc/html/umontreal/iro/lecuyer/randvar/WeibullGen.html
- http://www.icsa.inf.ed.ac.uk/research/groups/hase/simjava/distributions/doc/eduni/distributions/Weibull.html
- http://www.ee.ucl.ac.uk/~mflanaga/java/PsRandom.html
One way to generate a random number from a given distribution is to generate a random number uniformly distributed between zero and one, and apply the target distribution's inverse CDF to that random number. See Wikipedia.
Problem
I am trying to model shadowing and fast fading for mobile wireless networks. For fast fading, Rayleigh fading is a reasonable model to use. The envelope of the channel response will be Rayleigh distributed. Calling this random variable R, it will have a probability density function (PDF) of PR(r) = ((2r)/Ω)*exp(-r^2/Ω), r >= 0, Ω = 2σ^2 http://en.wikipedia.org/wiki/Rayleigh_fading to see the equation written nicely. So, I have the PDF, now I am just wondering how to get the random variable from it? I have looked at these questions: Generate Array of Numbers that fit to a Probability Distribution in Ruby? Generate Random Numbers with Probabilistic Distribution but I am still not sure how to do it. It has taken me forever to understand PDF's so if anyone knows a way in Java to get a random variable with a specific PDF, that would be much appreciated!