Random.nextGaussian() is supposed to give random no.s with mean 0 and std deviation 1. Many no.s it generated are outside range of [-1,+1]. how can i set so that it gives n
A Gaussian distribution with a mean 0 and standard deviation one means that the average of the distribution is 0 and about 70% of the population lies in the range [-1, 1]. Ignore the numbers that are outside your range -- they form the fringe 16% approx on either side.
Maybe a better solution is to generate a distribution with mean=0 and std.dev=0.5. This will give you a distribution with about 96% of the values in the range [-1, 1].
An even better solution is to work backward as above and use the idea that approx. 99.7% of the values lie in the 3-sigma range: use a std.dev = 1/3. That will almost nullify the amount of not-so-useful values that you are getting. When you do get one, omit it.
Of course, if you are working on a math intensive product, all of this bears no value.