I use C++ GSL library to generate random numbers now. The numbers obey a distribution, (e.g. normal or lognormal distribution). This library requires the input of expected value ${\mu}$ (i.e. mean) and std. deviation $\sigma$. I'd like sample random numbers within an interval $(a, b)$. So, when the generated numbers is out of the interval, then that number is discarded. For instance, I'd like to sample numbers having a normal distribution with $\mu$ = 5, $\sigma$ = 0.5, $a$ = 0.5, and $b$ = 10. The $\mu$ must be in the interval $(a, b)$.

The question is: someone said the input $\mu$ and $\sigma$ are not true $\mu$ and $\sigma$ of the sampled numbers, because the pdf $f(x)$ is truncated. But I think, since the input $\mu$ is within the $(a, b)$, and $(a, b)$ is wide enough, they might not be so different.

Is it a big difference between the input and true $\mu$ and $\sigma$? Is it anyway to analytically derive the true values of them?

Maybe, the true $\mu$ is $E(x) = \int_a^bxf(x)dx$? am I right?

  • 3
    $\begingroup$ Wikipedia Truncated distribution -- the sidebar has the doubly-truncated mean $\endgroup$
    – Glen_b
    Jul 15, 2021 at 6:56

2 Answers 2


Suppose that $G$ is an absolutely continuous distribution, perhaps with support on all real numbers, or some other interval, and $F$ is a truncated distribution with the same pdf, except that it is restricted to have support on $[a,b]$. To write it out in notation,

$$ f(x)= \begin{cases} C g(x) & x\in[a,b] \\ 0 &\text{otherwise} \end{cases} $$

for some constant $C$ which renormalizes the distribution.

When $G$ is an absolutely continuous distribution, we can write the CDF of $F$ as $$ F(x) = \frac{G(x)-G(a)}{G(b) - G(a)} $$

and by LOTUS, the distribution $F$ has expectation

$$ \mu=\frac{\int_a^b t d G(t)}{G(b)-G(a)} $$

and variance

$$ \sigma^2 =\frac{\int_a^b t^2 d G(t)}{G(b)-G(a)} - \mu^2. $$


For truncated distributions, it is customary to parameterise them in terms of the original parameters, ie those of the untruncated distribution. For instance, the truncated normal distribution$$\mathcal N_-^+(\mu,\sigma^2,a,b)$$restricts the untruncated normal distribution$$\mathcal N_(\mu,\sigma^2)$$to the interval $(a,b)$, meaning that the untruncated normal $\mathcal N_(\mu,\sigma^2)$ density is restricted to the $(a,b)$ interval and renormalised$$f_-^+(x;\mu,\sigma^2,a,b)=\varphi(x;\mu,\sigma^2)\Big/\int_a^b\varphi(\xi;\mu,\sigma^2)\,\text d\xi\tag{1}$$Using the original mean-variance parameterisation is easier than using the truncated mean-variance parameterisation as

  1. The definition of the distribution is straightforward, as shown by (1). By contrast, if given the truncated mean-variance parameterisation, one would need to revert back to the untruncated mean-variance parameterisation to write (1).
  2. In most situations, there exist no analytical formula for the mean and/or variance of the truncated distributions. Take for instance a truncated multivariate Normal distribution.

Note however that the truncated normal distribution$$\mathcal N_-^+(\mu,\sigma^2,a,b)$$ allows for$$\sigma^2<0$$when $a$ and $b$ are both finite. Meaning that $$\exp\{(x-\mu)^2/2\kappa\}\Big/\int_a^b \exp\{(\xi-\mu)^2/2\kappa\}\,\text d\xi$$ is well-defined for all $\kappa\in\mathbb R$.

Note also that simulating from the untruncated version until the outcome stands in $(a,b)$ may prove a very inefficient way of simulating from the truncated version.

  • $\begingroup$ Thanks. there is no analytical formula. so, can I deem the original (input) $\mu$ and $\sigma$ as the true mean and variance of the generated numbers? I think they might be different, but since the input $\mu$ stands in $(a, b)$, they might be close. $\endgroup$ Jul 15, 2021 at 8:53
  • $\begingroup$ No no no : $\mu$ and $\sigma$ are natural parameters of the truncated distribution, but they are definitely not its mean and variance, respectively. The fact that an analytical closed form formula does not exist does not mean that the true mean and variance do not exist. $\endgroup$
    – Xi'an
    Jul 15, 2021 at 9:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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