Stan Math Library  2.11.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 
24 namespace stan {
25 
26  namespace math {
27 
28  template <class RNG>
29  inline int
30  binomial_rng(const int N,
31  const double theta,
32  RNG& rng) {
33  using boost::variate_generator;
34  using boost::binomial_distribution;
35 
36  static const char* function("stan::math::binomial_rng");
37 
42 
43  check_nonnegative(function, "Population size parameter", N);
44  check_finite(function, "Probability parameter", theta);
45  check_less_or_equal(function, "Probability parameter", theta, 1.0);
46  check_greater_or_equal(function, "Probability parameter", theta, 0.0);
47 
48  variate_generator<RNG&, binomial_distribution<> >
49  binomial_rng(rng, binomial_distribution<>(N, theta));
50  return binomial_rng();
51  }
52 
53  }
54 }
55 #endif
bool check_greater_or_equal(const char *function, const char *name, const T_y &y, const T_low &low)
Return true if y is greater or equal than low.
bool check_less_or_equal(const char *function, const char *name, const T_y &y, const T_high &high)
Return true if y is less or equal to high.
bool check_finite(const char *function, const char *name, const T_y &y)
Return true if y is finite.
bool check_nonnegative(const char *function, const char *name, const T_y &y)
Return true if y is non-negative.
int binomial_rng(const int N, const double theta, RNG &rng)

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