GaussianAndBinomial
From SGenomics
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 representation of the Binomial distribution in continuous space. 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;
}
space[final]++;
}
for(int n=0;n<space.size();n++) {
cout << n << " " << space[n] << endl;
}
return 0;
}
Here's the gnuplot generated from the output:

