1 #ifndef STAN_MATH_PRIM_MAT_PROB_MULTINOMIAL_RNG_HPP
2 #define STAN_MATH_PRIM_MAT_PROB_MULTINOMIAL_RNG_HPP
12 #include <boost/math/special_functions/gamma.hpp>
13 #include <boost/random/uniform_01.hpp>
14 #include <boost/random/variate_generator.hpp>
22 inline std::vector<int>
26 static const char*
function(
"stan::math::multinomial_rng");
33 std::vector<int> result(theta.size(), 0);
34 double mass_left = 1.0;
36 for (
int k = 0; n_left > 0 && k < theta.size(); ++k) {
37 double p = theta[k] / mass_left;
41 mass_left -= theta[k];
bool check_positive(const char *function, const char *name, const T_y &y)
Return true if y is positive.
std::vector< int > multinomial_rng(const Eigen::Matrix< double, Eigen::Dynamic, 1 > &theta, const int N, RNG &rng)
bool check_simplex(const char *function, const char *name, const Eigen::Matrix< T_prob, Eigen::Dynamic, 1 > &theta)
Return true if the specified vector is simplex.
int binomial_rng(const int N, const double theta, RNG &rng)