I want to generate data for vector 'y' between 'x_min' and 'x_max'. The data need to be generated to be in such a way that they would return certain 'mu' and 'sigma' if I fit them for normal distribution. Can you advise please?
You won't be able to accomplish this for general x_min, x_max, mu, and sigma. The reason is that the probability density function of a normal distribution is nonzero over the open interval (-inf,inf).
However, you can do reasonably well if, for example, x_min - 3*sigma < mu < x_max + 3*sigma. Then, when you randomly generate data in accordance with a normal distribution, pretty much all of the data you generate will lie between x_min and x_max. Just throw out those that don't.
In MATLAB, for a sample of approximate size n (it may end up being a little less), you can do it in three lines of code.
y = sigma*randn(n,1) + mu; % Data from N(mu,sigma^2)
Why are you trying to coerce a normal distribution into a defined range? What are you trying to simulate? There may be better ways of generating data that more closely mirror the data generation process you are interested in.
You can use the acceptance-rejection method to generate random numbers that satisfy certain 'mu' and 'sigma' for normal distribution f(x). The algorithm to obtain a sample from distribution with normal density f(x) is as follows:
1.Generate a value of a random variable Xi with uniform distribution from (x_min, x_max).
2.Generate a value of a random variable Yi with uniform distribution from (0, f_max).
The Box-Muller method is the most used for generating random normal distributed numbers. It’s very easy to implement and you can used in any language that has a built-in uniform number generator.