Let $X$ be a Gaussian random variable where for simplicity, $X \sim N(0,1)$. I am interested in generating samples of $X$ in the following cases: $X \mid X \in (a,b)$ where $a < b$ or $X \mid X > b$. I am aware that I can do rejection sampling for this and especially for the latter, Wikipedia says (under rejection sampling) that exponential tilting is a very efficient manner to generate samples for $X \mid X>b$. I am wondering though: is there a better way to do this without rejection sampling? In other words, do algorithms exist wherein the above scenarios can be sampled by just a simple scaling/translation of a random variable that can be easily sampled?

Thoughts/comments appreciated. Thanks!


It is easy enough if you have the cumulative distribution function $\Phi(x)$ and inverse cumulative distribution function $\Phi^{-1}(y)$ of a standard normal distribution:

  • Generate $U$ uniformly distributed on the interval $(\Phi(a),\Phi(b))$
  • Let $X = \Phi^{-1}(U)$

and if you just want to ensure $X \gt a$ then $b=+\infty$ and $\Phi(b)=1$

For example in R:

a <- 2
b <- 3
n <- 8
qnorm(runif(n, min=pnorm(a), max=pnorm(b))) 


[1] 2.118457 2.175760 2.308311 2.714952 2.087221 2.694532 2.802697 2.382023
  • $\begingroup$ Wow. That was so simple. Never thought of it this way. Thanks!!! $\endgroup$ – Tomas Jorovic Jul 17 '18 at 2:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.