# Initializing Stan Model object with random\_seed - all interfaces should use 3-arg constructor

**URL:** https://discourse.mc-stan.org/t/initializing-stan-model-object-with-random-seed-all-interfaces-should-use-3-arg-constructor/556
**Category:** Developers
**Created:** [May 15, 2017, 6:32pm UTC](https://discourse.mc-stan.org/t/initializing-stan-model-object-with-random-seed-all-interfaces-should-use-3-arg-constructor/556 "2017-05-15T18:32:51Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![mitzimorris](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mitzimorris/32/29_2.png) [@mitzimorris](https://discourse.mc-stan.org/u/mitzimorris)
#### Post date: [May 15, 2017, 6:32pm UTC](https://discourse.mc-stan.org/t/initializing-stan-model-object-with-random-seed-all-interfaces-should-use-3-arg-constructor/556/1 "2017-05-15T18:32:51Z")

</div>

Investigated bug [https://github.com/stan-dev/stan/issues/2241](https://github.com/stan-dev/stan/issues/2241), which reports that in rstan, RNG functions called from the transformed data block are always using the same seed value of `0`, even when the random seed is overtly specified. cmdstan has the same problem.

This is due to the fact that the stan model object has both a 2-arg and 3-arg constructor. The 3-arg constructor takes an instantiated boost rng object; the 2-arg constructor instantiates such an object with seed `0`.

I put a fix in for cmdstan - we need something similar for rstan and we should check all other interfaces - pystan, etc.

---

<div class="post-metadata">

### Author: ![Bob\_Carpenter](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bob_carpenter/32/9230_2.png) [@Bob\_Carpenter](https://discourse.mc-stan.org/u/Bob_Carpenter)
#### Post date: [May 15, 2017, 6:41pm UTC](https://discourse.mc-stan.org/t/initializing-stan-model-object-with-random-seed-all-interfaces-should-use-3-arg-constructor/556/2 "2017-05-15T18:41:54Z")

</div>

Thanks for tracking that down. Would you mind creating issues for RStan and PyStan and linking back to the suggested fix?

---

<div class="post-metadata">

### Author: ![mitzimorris](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mitzimorris/32/29_2.png) [@mitzimorris](https://discourse.mc-stan.org/u/mitzimorris)
#### Post date: [May 15, 2017, 6:58pm UTC](https://discourse.mc-stan.org/t/initializing-stan-model-object-with-random-seed-all-interfaces-should-use-3-arg-constructor/556/3 "2017-05-15T18:58:16Z")

</div>

done!

> <https://github.com/stan-dev/pystan/issues/341>
>
> Summary:
> Check whether or not in pystan the RNG in the transformed data block is insensitive to seed.
> See stan-dev/stan#2241 for details.

  

> <https://github.com/stan-dev/rstan/issues/413>
>
> Summary:
> The RNG in the transformed data block is insensitive to seed. It should use the overall seed, but not the chain...

---

<div class="post-metadata">

### Author: ![mitzimorris](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mitzimorris/32/29_2.png) [@mitzimorris](https://discourse.mc-stan.org/u/mitzimorris)
#### Post date: [May 16, 2017, 6:43pm UTC](https://discourse.mc-stan.org/t/initializing-stan-model-object-with-random-seed-all-interfaces-should-use-3-arg-constructor/556/4 "2017-05-16T18:43:21Z")

</div>

Further discussion raises the following questions:

- do we want to keep the feature allow RNG in transformed data block?
- per the above formulation, “it should use the overall seed, but not the chain”, would it make sense to change the Model 3-arg constructor to accept the seed instead of an RNG object?
- should we file a new issue to fix the generated code so that the 2-arg constructor will try to generate a random seed instead of using `0`?

---

<div class="post-metadata">

### Author: ![mitzimorris](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mitzimorris/32/29_2.png) [@mitzimorris](https://discourse.mc-stan.org/u/mitzimorris)
#### Post date: [May 16, 2017, 6:52pm UTC](https://discourse.mc-stan.org/t/initializing-stan-model-object-with-random-seed-all-interfaces-should-use-3-arg-constructor/556/5 "2017-05-16T18:52:21Z")

</div>

I missed out on previous discussion of this feature - it seems like we want any randomly generated data in the transformed data block to be the same for all chains, correct?
