c++pythonalgorithmrandommontecarlo

Is there a way to generate a random variate from a non-standard distribution without computing CDF?


I'm trying to write a Monte Carlo simulation. In my simulation I need to generate many random variates from a discrete probability distribution.

I do have a closed-form solution for the distribution and it has finite support; however, it is not a standard distribution. I am aware that I could draw a uniform[0,1) random variate and compare it to the CDF get a random variate from my distribution, but the parameters in the distributions are always changing. Using this method is too slow.

So I guess my question has two parts:

  1. Is there a method/algorithm to quickly generate finite, discrete random variates without using the CDF?

  2. Is there a Python module and/or a C++ library which already has this functionality?


Solution

  • Acceptance\Rejection: Find a function that is always higher than the pdf. Generate 2 Random variates. The first one you scale to calculate the value, the second you use to decide whether to accept or reject the choice. Rinse and repeat until you accept a value. Sorry I can't be more specific, but I haven't done it for a while.. Its a standard algorithm, but I'd personally implement it from scratch, so I'm not aware of any implementations.