Index: include/random =================================================================== --- include/random +++ include/random @@ -2337,7 +2337,7 @@ for (size_t __i = 1; __i < __n; ++__i) if (__x_[__i] != 0) return; - __x_[0] = _Max; + __x_[0] = result_type(1) << (__w - 1); } } @@ -2363,7 +2363,7 @@ for (size_t __i = 1; __i < __n; ++__i) if (__x_[__i] != 0) return; - __x_[0] = _Max; + __x_[0] = result_type(1) << (__w - 1); } } Index: test/std/numerics/rand/rand.eng/rand.eng.mers/ctor_sseq_all_zero.pass.cpp =================================================================== --- test/std/numerics/rand/rand.eng/rand.eng.mers/ctor_sseq_all_zero.pass.cpp +++ test/std/numerics/rand/rand.eng/rand.eng.mers/ctor_sseq_all_zero.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// class mersenne_twister_engine; + +// template explicit mersenne_twister_engine(Sseq &q); +// +// [ ... ] Finally, if the most significant $w-r$ bits of $X_{-n}$ are zero, +// and if each of the other resulting $X_i$ is $0$, changes $X_{-n}$ to +// $ 2^{w-1} $. + +#include + +#include +#include +#include +#if TEST_STD_VER >= 11 +#include +#endif + +struct all_zero_seed_seq { + typedef unsigned int result_type; + + all_zero_seed_seq() {} + + template + all_zero_seed_seq(InputIterator, InputIterator) {} +#if TEST_STD_VER >= 11 + all_zero_seed_seq(std::initializer_list) {} +#endif + + template + void generate(RandomAccessIterator rb, RandomAccessIterator re) { + std::fill(rb, re, 0u); + } + + std::size_t size() const { return 0u; } + template void param(OutputIterator) const {} +}; + +template +void test(void) { + const std::size_t state_size = 1u; + const std::size_t shift_size = 1u; + const std::size_t tempering_l = word_size; + + all_zero_seed_seq q; + std::mersenne_twister_engine + e(q); + + const result_type Xneg1 = result_type(1) << (word_size - 1); + const result_type Y = Xneg1; + const result_type X0 = Xneg1 ^ (Y >> 1); + assert(e() == X0); +} + +int main() { + // Test for k == 1: word_size <= 32. + test(); + + // Test for k == 2: (32 < word_size <= 64). + test(); +}