I need to draw random integers from a truncated discrete Gaussian distribution. That is, the probability of integer $i$ is:
$$p_i \propto \exp\left( -\frac{(i-\mu)^2}{2\sigma^2} \right)$$
for $a \le i \le b$, and $p_i = 0$ otherwise. The missing proportionality constant is obtained from the normalization condition, $\sum_i p_i = 1$. Here $\mu$ and $\sigma$ are real parameters.
Is there a way (package, algorithm, trick, anything) to sample this distribution?
sample-- if numerical issues (like underflow say) are not going to be at issue, you don't actually even need to normalize them (sample(a:b,n,p=dnorm(a:b,mu,sigma),replace=TRUE)). – Glen_b Oct 25 '17 at 09:16