Sunday, March 1, 2009

Gaussian and Binomial distributions

I'm most probably being entirely stupid here...

I've been trying to understand the Gaussian distribution and it's relation to the Binomial distribution. I've kind of decided that the Gaussian distribution is a continuous representation of the Binomial distribution. Is this correct?

Anyway, here is some C++ which creates a binomial distribution by adding n random values (-1,0 or 1) to a fixed initial value. I think for this as a kind of 2D random walk. Here's the code:

#include <vector>
#include <iostream>
#include <math.h>

using namespace std;

int main(void) {

vector<size_t> space(100,0);

size_t tries=1000000;
size_t offset=50;
for(size_t n=0;n<tries;n++) {

size_t moves=1000;

int final=50;
for(size_t t=0;t<moves;t++) {
int val = rand()%3;
val -= 1;

final +=val;

for(int n=0;n<space.size();n++) {
cout << n << " " << space[n] << endl;

return 0;

Here's the gnuplot generated from the output:

If you have any pointer on the link between Binomial and Gaussian distributions explained in a way a computer scientist can understand please add them below.

1 comment:

new said...

One of the things that I've found when looking for information on this is the number of documents that show you the formula for say the Gaussian distribution and tell you how to use it. But very few explain why this is so, or how it is motivated.