How do you sample $\mathcal N(\mu, \sigma^2)$ from a range? How can we generate a sample in the interval $[a,b]$ based on a Gaussian distribution?
If we have a Gaussian random generator, just by mapping the number to the range and pruning (ignoring) the values outside of the range, does our sample still follow the Gaussian distribution? In short, how correct is this approach?

added later :
assume we can generate $\mathcal N(\mu, \sigma^2)$ with any parameters, now with given [a,b] , is there a way to chose  a relatively good $\mathcal (\mu)$ and $\mathcal (\sigma)$ ? for example  $\mathcal \mu = (a+b)/2$  &  $\mathcal \sigma = (b - \mu)/3$
 A: While several posts on site link to things that at least mention your proposed algorithm, and some posts seem to mention it in passing, I didn't locate a post that directly discussed it in enough detail to really count as answered on this site. As a result I think it's worth discussing briefly here, but you should refer to the posts I linked in comments -- Simulate from a truncated mixture normal distribution (and the linked paper there), and  Simulate constrained normal on lower or upper bound in R -- for good algorithms.

*

*You can get truncated normals in the way you suggest - by generating normals and throwing out values outside the truncation bounds - so it is correct but it's usually not used (except as part of a series of possible methods) because it can be very inefficient.
Consider for example if you have $\mu=0$, $\sigma=1$ but $a=4$ and $b=5$. Your method would generate over thirty-thousand normal values for every one it kept. It works fairly well when both $a<\mu-\sigma$ and $b>\mu+\sigma$ (though it can be used when they aren't both outside that range if need be).


*Another method that can be useful when $a$ and $b$ are both close to $\mu$ (say both between $\mu-\sigma$ and $\mu+\sigma$) is to sample a random point in the rectangle with base (a,b) and height the maximum height of the normal density in the interval, then return the ordinate of the point if the point falls under the normal density (otherwise reject it and generate again). This is a different form of accept-reject to that in 1., and useful in different circumstances. It's fairly easy to compute the rejection rates of the two approaches in 1 and 2, so if the cost of generating two uniforms isn't much different from the cost of generating one normal you'd pick the one with the lower rejection rate.


*You can also use the inverse cdf method. This can work quite well.


*In the extreme tails you can use accept-reject with an exponential majorizing function (an approach I first read about something like 30 years ago, but I can't locate the reference at the moment).
More details of these other options are available in the resources previously mentioned.
