Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm a software engineer. I asked a friend for help easily creating a somewhat-normal distribution. This is just for the purpose of adding entropy to an application.

The code he gave me is this:

(rand(-1000, 1000) + rand(-1000, 1000) + rand(-1000, 1000)) / 100

If I run this 1000 times, it produces results between -27 and 28, with a good-enough normal distribution:

Mean: -0.671 Median: -1 Std Dev: 9.9

I'm not as good at math as I should be. Can anybody help me understand why this works?

share|cite|improve this question
First of all the binomial distribution has parameters p and n and takes values on the integers from 0 to n. So what you get from a scaled value of the sum of three independent uniforms is not binomial. It will be roughly normal by the CLT as Xoff points out. But I don't see how explaining that something is approximately normal answers the question "Why does this look somewhat binomial?" It doesn't look binomial at all! – Michael Chernick Aug 7 '12 at 20:37
Ok, I would be just as critical if you misused software engineering terms. So appreciate the correction. ---- So why does this look "somewhat normal" ? – Encoderer Aug 7 '12 at 20:41
The central limit theorem says that averages of random variables that are independent and identically distributed (with certain conditions on existence of moments) will approach the normal distribution as n gets large. In this case n is only 3 but the approximation is starting to work. – Michael Chernick Aug 7 '12 at 20:51
up vote 5 down vote accepted

The central limit theorem says that if you sum enough similar random variables, you will get something that will be close to a normal law. Your solution (add 3 variables) is not really good, but it's a start.

There are far better solutions, like the Box–Muller transform, who will generate almost perfect normally distributed variables.

share|cite|improve this answer
A "poor man's normal random variable generator" sums $12$ random variables uniformly distributed on $(0,1)$, e.g. the results of $12$ calls to rand() in many computer languages, and subtracts $6$. This gives a number in $(-6,6)$ that can be taken as a sample of a $\mathcal N(0,1)$ random variable. The choice of $12$ samples allows elimination of a division to get the scaling correct: variance to be $1$. Of course, the Box-Muller transform gives better results..... – Dilip Sarwate Aug 7 '12 at 21:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.