feat: add a binomial distribution to eo::rng

Note: use the most naive algorithm, should be a rejection one.
This commit is contained in:
Johann Dreo 2020-07-05 18:00:51 +02:00
commit 1cdb134ee2

View file

@ -216,6 +216,19 @@ public :
return uniform() < bias;
}
/** Sample in a binomial dsitribution of size n and probability p.
FIXME most naive algorithm, one should really use a rejection algorithm.
*/
unsigned binomial(unsigned n, double p)
{
unsigned x = 0;
for(unsigned i=0; i<n; ++i) {
x += flip(p);
}
return x;
}
/** Gaussian deviate
Zero mean Gaussian deviate with standard deviation 1.