0
$\begingroup$

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?

  • 1
    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!2012-08-07
  • 0
    Ok, I would be just as critical if you misused software engineering terms. So appreciate the correction. ---- So why does this look "somewhat normal" ?2012-08-07
  • 1
    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.2012-08-07

1 Answers 1

5

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.

  • 3
    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.....2012-08-07