I am trying to generate a Geometric random variable. My code is:

generated quantities{

real theta[I];

int lifetime[I];for (i in 1:I) {

theta[i] = beta_rng(a, b);

lifetime[i] = neg_binomial_rng(1 ,theta[i]/(1-theta[i]) ) ;

}}

But I get the following error:

Exception: neg_binomial_rng: Random number that came from gamma distribution is 5.58759e+09, but must be less than 1.07374e+09

I believe Stan is trying to generate a really large number. Is there a way to preempt this error by telling Stan to give some number (that I am ok with) when this issue happens? Thanks.

EDIT: I extracted *theta* and I see that some values are very small. Is there a way to circumvent those small values by placing a lower limit (say, 1e-7)?