Stan Math Library  2.15.0
reverse mode automatic differentiation
binomial_rng.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_PROB_BINOMIAL_RNG_HPP
2 #define STAN_MATH_PRIM_SCAL_PROB_BINOMIAL_RNG_HPP
3 
4 #include <boost/random/binomial_distribution.hpp>
5 #include <boost/random/variate_generator.hpp>
22 
23 namespace stan {
24  namespace math {
25 
39  template <class RNG>
40  inline int
41  binomial_rng(int N,
42  double theta,
43  RNG& rng) {
44  using boost::variate_generator;
45  using boost::binomial_distribution;
46 
47  static const char* function("binomial_rng");
48 
49  check_nonnegative(function, "Population size parameter", N);
50  check_finite(function, "Probability parameter", theta);
51  check_less_or_equal(function, "Probability parameter", theta, 1.0);
52  check_greater_or_equal(function, "Probability parameter", theta, 0.0);
53 
54  variate_generator<RNG&, binomial_distribution<> >
55  binomial_rng(rng, binomial_distribution<>(N, theta));
56  return binomial_rng();
57  }
58 
59  }
60 }
61 #endif
void check_finite(const char *function, const char *name, const T_y &y)
Check if y is finite.
void check_less_or_equal(const char *function, const char *name, const T_y &y, const T_high &high)
Check if y is less or equal to high.
void check_nonnegative(const char *function, const char *name, const T_y &y)
Check if y is non-negative.
void check_greater_or_equal(const char *function, const char *name, const T_y &y, const T_low &low)
Check if y is greater or equal than low.
int binomial_rng(int N, double theta, RNG &rng)
Return a pseudorandom Binomial random variable for the given population size and chance of success pa...

     [ Stan Home Page ] © 2011–2016, Stan Development Team.