On 11 April 2017 at 21:17, Oliver Kullmann <o.kullmann@xxxxxxxxxxxxx> wrote: >> Now only missing seeding for std::mt19937_64. >> >> This seems most complicated. >> Apparently it is in >> https://gcc.gnu.org/viewcvs/gcc/trunk/libstdc%2B%2B-v3/include/bits/random.tcc?revision=246542&view=markup >> >> Lines 346 - 389. >> >> I would guess that this functionality is most specialised, and most likely to be different >> for different compilers. >> >> Really a pitty that this was not standardised. >> > > The code at Lines 346 - 389 for the seed-member of the > mersenne_twister_engine doesn't look too bad except of two aspects: What > is > > - __detail::_Shift ? > - __detail::__mod ? > > It seems that apart from these functions, everything else is just > arithmetic of bit-logic. > > And the creation of that sequence in Line 360: > __q.generate(__arr + 0, __arr + __n * __k); > actually seems to be defined by the standard, so that can be used. > > ACTUALLY, I just realise that even if I can code the above myself, I > couldn't use the Mersenne twister from the standard library, since > apparently the only way of setting the internal state is by > *constants*?? > > All what there is seems to be > http://www.cplusplus.com/reference/random/mersenne_twister_engine/ Use a better reference. http://en.cppreference.com is much better than cplusplus.com > template <class UIntType, size_t w, size_t n, size_t m, size_t r, > UIntType a, size_t u, UIntType d, size_t s, > UIntType b, size_t t, > UIntType c, size_t l, UIntType f> > class mersenne_twister_engine; > and that has the state, which is set by the seed-member-function, only as template parameter. > > So I need to implement the Mersenne twister apparently myself. > Or perhaps I don't understand that yet properly. > > Perhaps the seed function has nothing to do with those template parameters, which are the > parameters of the engine, while the seed sets only the "internal state", and that perhaps > can be done explicitly by calling some std-library facility? I don't understand what you're trying to do or what the difficulty is. The output of the mersenne_twister_engine is specified by the standard, there should be no need to reimplement it. If you don't get repeatable values for any implementation of mersenne_twister_engine then it's a bug in that implementation. The template arguments are just parameters for the internal algorithm, so different parameters create different outputs. std::mt19937 is simply a specialization of the mersenne_twister_engine with parameters that are known to produce good pseudo-random numbers. The behaviour of uniform_int_distribution is also specified by the standard, but only the mathematical properties, not a specific implementation. That means different implementations can give different outputs. If you use your own uniform_int_distribution then you ensure repeatable outputs across implementations. I repeat, there should be no need to do that with the engines themselves.