# How to generate from this distribution without inverse in R/Python?

I am working with a distribution with the following density: $$f(x) = - \frac{(\alpha+1)^2 x^\alpha \log(\beta x)}{1-(\alpha + 1)\log(\beta)}$$ and CDF $$\mathbb{P} (X \leq x) = \int_0^x - \frac{(\alpha+1)^2 t^\alpha \log(\beta t)}{1-(\alpha + 1)\log(\beta)} \, dt = \frac{x^{\alpha+1}((\alpha+1)(\log(\beta x))-1)}{(\alpha+1)\log(\beta)-1}$$ with $$x \in (0,1), \beta \in (0,1)$$ and $$\alpha >-1.$$ How can I generate random samples from this distribution in Python/R? Which books can I use to learn about the simulation of random variables and random numbers? Any help is appreciated.

• You could try the no u turn sampler if you confirm the likelihood is almost everywhere smooth. Apr 9 at 15:20
• For completeness, it might be worth clarifying what happens in the case where $\log(\beta) = \tfrac{1}{\alpha+1}$ (where you have denominators of zero).
– Ben
Apr 10 at 22:13
• Voting to reopen: I disagree strongly that this question is anything other than "a statistical topic disguised as a coding question." Also this may be a good resource Devroye, L. (1986). Non-Uniform Random Variate Generation. Springer Verlag. Apr 10 at 23:09
• The parameter $\alpha$ can be "swallowed" by the change of variable $z=x^{\alpha+1}$, reducing to $\mathbb P(Z\le z)=z(\gamma\log z+1)$. Apr 11 at 6:47

A quick and dirty solution is to apply the inverse transform sampling in which the quantile function is computed via numerical inversion. Below is an R implementation along with an example.

# (your density)
myf <- function(x, a, b) {
num = (a+1)**2 * x**a * log(b*x)
den = 1 - (a+1)*log(b)
return(-num/den)
}