# Alternative to set.seed()

I want to use different seeds in generated quantities block as follows.
But, set.seed does not work. Is there any alternative to set.seed() ?

    data { ... }
parameters {real <lower = 0, upper =1> theta;}
model {...}

generated quantities{
int n[100];

for(i in 1:100) {
set.seed(i)  ; # This does not work----------------------
n[i] = bernoulli_rng(theta);
}

}

Is set.seed Stan syntax or R?

Why do you need this? Is there something specific you want to do?

set.seed is an R syntax from base package.

What I want is the calculation of the quantity \int \int T(y,\theta) f(y|\theta)p(\theta|y_0) dy d\theta which is approximated by the sum \sum \sum T(y_{ij},\theta_i)/I J, where f is a likelihood,and p(\theta|y_0) denotes a posterior for given data y_0 and y_{ij} \sim f(*|\theta_i) and \theta_i \sim p(*|y_0), i= 1,\cdots I and j= 1,\cdots J, and T(y,\theta) is a function depending on both data y and model parameter \theta. To draw such J samples \{y_{ij};j=1,\cdots, J\}, I want to use various seeds in generated quatities block. If without seeds, then I can draw only in case of J=1.

R syntax doesn’t work in Stan language.

Each time _rng function is called PRNG is advanced. Do you want to reset the PRNG to use the same numbers? Otherwise I don’t get why you need to set a new seed.

I am sorry, I don’t know about PRNG.
I maybe misunderstand.
Do you mean that, in the following code, each n[i] is already distinct without changing seed? I guess, different seeds are redundant…

  for(i in 1:100) {
n[i] = bernoulli_rng(theta);
}

Yes.

(Sorry for throwing acronyms around: PRNG -> pseudo random number generator)

I’m sorry, I was completely wrong.
I misunderstood that to change samples I also need to change seed.

Thank you