Stan Math Library  2.6.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
beta_binomial_rng.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_PROB_BETA_BINOMIAL_RNG_HPP
2 #define STAN_MATH_PRIM_SCAL_PROB_BETA_BINOMIAL_RNG_HPP
3 
19 
20 namespace stan {
21 
22  namespace math {
23 
24  template <class RNG>
25  inline int
26  beta_binomial_rng(const int N,
27  const double alpha,
28  const double beta,
29  RNG& rng) {
30  static const char* function("stan::math::beta_binomial_rng");
31 
34 
35  check_nonnegative(function, "Population size parameter", N);
36  check_positive_finite(function,
37  "First prior sample size parameter", alpha);
38  check_positive_finite(function,
39  "Second prior sample size parameter", beta);
40 
41  double a = stan::math::beta_rng(alpha, beta, rng);
42  while (a > 1 || a < 0)
43  a = stan::math::beta_rng(alpha, beta, rng);
44  return stan::math::binomial_rng(N, a, rng);
45  }
46  }
47 }
48 #endif
double beta_rng(const double alpha, const double beta, RNG &rng)
Definition: beta_rng.hpp:30
int beta_binomial_rng(const int N, const double alpha, const double beta, RNG &rng)
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)
bool check_positive_finite(const char *function, const char *name, const T_y &y)
Return true if y is positive and finite.

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