thanks for the info. My first, little, basically trivially success, is replacing the Bernoulli-distribution for the default case: inline bool bernoulli(std::mt19937_64& g) noexcept { typedef std::mt19937_64::result_type uint_t; constexpr uint_t half = std::numeric_limits<uint_t>::max() / 2; return g() < half; } Checked that it reproduces the behaviour of gcc 4.7.4 and 5.4. Replacing std::uniform_int_distribution (only for std::mt19937_64) seems harder, and yet I have problems understanding the code. One could just generalise the above, and since only 32-bits intervals are used, that likely would suffice for a decent distribution. However g++ seems to do something more advanced. On Sun, Apr 09, 2017 at 05:31:54PM -0600, Martin Sebor wrote: > It's worth keeping in mind that copying libstdc++ code will have > licensing implications. A different caveat is that conforming C++ > programs can define explicit specializations of standard library > templates only for user-defined types. I.e., it's not valid to > define one's own std::uniform_int_ditribution class template or > specialization of it on a fundamental type such as int. > I just want to extract the mathematical content, and then write simple code for it, like above. If somebody knows some underlying papers describing the algorithms for uniform_int_distribution and seeding std::mt19937_64, that would be great. > Another option is to browse the sources online: > > https://gcc.gnu.org/viewcvs/gcc/trunk/libstdc%2B%2B-v3/include/bits/random.h?view=markup > Thanks, I found that most useful. Oliver