From 1cdb134ee2cee54ba29d2e3df606a8438da59c39 Mon Sep 17 00:00:00 2001 From: nojhan Date: Sun, 5 Jul 2020 18:00:51 +0200 Subject: [PATCH] feat: add a binomial distribution to eo::rng Note: use the most naive algorithm, should be a rejection one. --- eo/src/utils/eoRNG.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/eo/src/utils/eoRNG.h b/eo/src/utils/eoRNG.h index b26337ff9..d044e2500 100644 --- a/eo/src/utils/eoRNG.h +++ b/eo/src/utils/eoRNG.h @@ -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