0

Short question I couldn't find an answer to: I have two instances g1 and g2 of std::mt19937. If I seed g1 and g2 with a common int x, is it guaranteed that the sequence of samples generated by g1 is the same as the sequence of samples generated by g2 (assuming the same distributions are used, of course)? Or is this an "instance seed", i.e. is it only guaranteed that I may reproduce the sequence generated by the particular instance g1 if I reseed it later to x again?

0xbadf00d
  • 17,405
  • 15
  • 67
  • 107
  • @Evg What precisely do you mean? Say `std::uniform_real_distribution<> d1` and `std::normal_distribution<> d2`. You mean I shouldn't call `d1(g1)` and `d2(g1)`, i.e. better use another generator for `d2`? – 0xbadf00d Jan 09 '20 at 15:15
  • I mean that `g1()` and `g2()` will produce the same sequences that are independent of the standard library implementation. – Evg Jan 09 '20 at 15:17
  • @Evg Didn't you wrote something about distributions? – 0xbadf00d Jan 09 '20 at 15:22
  • I did, but deleted it because the dupe explains it. Both, `mt19937` and `uniform_real_distribution` generate random numbers. For generators you have such a guarantee, but for distributions you don't. Given that `g()` generates the same sequence for the same seed, `uniform_real_distribution` should also generate the same sequence for each particular library implementation. But it seems that this property is not guaranteed by the standard. – Evg Jan 09 '20 at 15:27
  • @Evg Maybe I've got a major misunderstanding, but doesn't `uniform_real_distribution` generated the samples based on the based generator? So, if we have to different `uniform_real_distribution d_1,d_2` and `g1, g2` have the same seed, the sequence produced by `d1(g_1)` and `d2(g_2)` should be identical, shouldn't they? – 0xbadf00d Jan 09 '20 at 15:39
  • That's correct. I don't see a way how they could not be identical in practice. The standard [says](http://eel.is/c++draft/rand.req.dist#3.8) that `D()` "creates a distribution whose behavior is indistinguishable from that of any other newly default-constructed distribution of type `D`." But what is "behavior"? Whether this condition strongly implies that `d1(g1)` and `d2(g2)` have to generate same sequences, I can't tell. – Evg Jan 09 '20 at 15:39

0 Answers0