How to generate a random number with a specific probability density function?

时光毁灭记忆、已成空白 提交于 2019-12-10 10:02:40

问题


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!


回答1:


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.




回答2:


For your case, something like this:

 Random generator = new Random();
 double r = Math.sqrt(-Omega*Math.log(1-generator.nextDouble()));


来源:https://stackoverflow.com/questions/13729243/how-to-generate-a-random-number-with-a-specific-probability-density-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!