feat: add a binomial distribution to eo::rng
Note: use the most naive algorithm, should be a rejection one.
This commit is contained in:
parent
75c2c6ab76
commit
1cdb134ee2
1 changed files with 13 additions and 0 deletions
|
|
@ -216,6 +216,19 @@ public :
|
||||||
return uniform() < bias;
|
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
|
/** Gaussian deviate
|
||||||
|
|
||||||
Zero mean Gaussian deviate with standard deviation 1.
|
Zero mean Gaussian deviate with standard deviation 1.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue