Scheduler
bernoulli.cpp
Go to the documentation of this file.
1 
10 #include "bernoulli.h"
11 #include <utils/randomGenerator.h>
12 #include <stdexcept>
13 
14 
15 using namespace Utils;
16 
17 
18 Bernoulli::Bernoulli(RandomGenerator *generator, double success_p)
19  : gen(generator)
20  , p(success_p)
21 {
22  if (p < 0.0 || p > 1.0)
23  throw std::domain_error("p should be between 0 and 1");
24 }
25 
26 
27 
29 {
30  double random = gen->drawUniform(0.0, 1.0);
31  if (random < p)
32  return 1.0;
33  return 0.0;
34 }
35 
double draw() override
returns a number from 0 to 1 following the underlying probability distribution
Definition: bernoulli.cpp:28
Definition: context.h:16
Bernoulli(RandomGenerator *gen, double p)
Definition: bernoulli.cpp:18
double drawUniform(double min, double max)