normal_distribution range.

Hey there, I'm implementing an normal_distribution to select objects on a vector. The thing is I can't use values greater then 1 or less then -1. Here is what could be done:
1
2
3
gausx=gaus_distributionx(generator);
while((gausx>1) || (gausx<-1))
   gausx=gaus_distributionx(generator);


The question is if the distribution would loose it's power to be a normal distribution, because some of the gerated numbers wouldn't be used.
If it does, anyone knows anyway to set ranges for the distribution?
The example output in http://www.cplusplus.com/reference/random/normal_distribution/
looks rather "normal", doesn't it?

A normal distribution with any standard deviation is a normal distribution. Just different.
My intention with this exemple would be to discard any value that is generated thats greater then 1 or less then -1. I'm talking about theese discarded values.
What you need is called truncated normal distribution. C++ has no standard way to do it.
First you can use your solution. However it has impact on perfomance. If it is no problem for you, use it.
Other way is to clamp result in your range. This have problem of creating spikes of probability on the ends of the range.
There is other ways but I think you would be fine with your first approach.
Yeah, the thing is this is a serious program for an article I'm writting at university.
I was doing some tests with the second parameter of the function the "standard deviation", I noticed that when I set it as 0.2 I only get values betwin -1 and 1. Anyone that know about probability could tell me more about this?
http://en.wikipedia.org/wiki/Standard_deviation

I noticed that when I set it as 0.2 I only get values betwin -1 and 1.

Insufficient testing. Draw more numbers and thou shall get bigger ones (once in a blue moon).
You just happens to get values between -1 and 1. Normal distribution has non-zero probability of generating any real number (with obvious implementaton limitations).

You can simulate truncated normal distribution: http://en.wikipedia.org/wiki/Truncated_normal_distribution#Simulating (Look for link to the C++ implementation)

If variance of normal distribution is not important to you, are you sure that you absolutely need normal distribution? Maybe beta distribution will suffice. Or maybe you even don't need continuous distribution and will be fine with one of discrete ones?
Last edited on
Topic archived. No new replies allowed.