From 8f72d5ce168d2f8237ada5196abf70a59a927236 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Tue, 21 May 2013 21:05:12 +0000 Subject: [PATCH] Fix a couple of bugs in linear_congruential_engine::seed. Regression test added. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@182421 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/random | 6 +++--- .../rand/rand.eng/rand.eng.lcong/seed_sseq.pass.cpp | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/random b/include/random index 92722ea6..f1076f97 100644 --- a/include/random +++ b/include/random @@ -1835,7 +1835,7 @@ public: // types typedef _UIntType result_type; -private: +//private: result_type __x_; static _LIBCPP_CONSTEXPR const result_type _Mp = result_type(~0); @@ -1880,7 +1880,7 @@ public: seed(_Sseq& __q) {__seed(__q, integral_constant());} + : (__m > 0x100000000ull))>());} // generating functions _LIBCPP_INLINE_VISIBILITY @@ -1969,7 +1969,7 @@ linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q, uint32_t __ar[__k+3]; __q.generate(__ar, __ar + __k + 3); result_type __s = static_cast((__ar[3] + - (uint64_t)__ar[4] << 32) % __m); + ((uint64_t)__ar[4] << 32)) % __m); __x_ = __c == 0 && __s == 0 ? result_type(1) : __s; } diff --git a/test/numerics/rand/rand.eng/rand.eng.lcong/seed_sseq.pass.cpp b/test/numerics/rand/rand.eng/rand.eng.lcong/seed_sseq.pass.cpp index 470726f7..ca2793c7 100644 --- a/test/numerics/rand/rand.eng/rand.eng.lcong/seed_sseq.pass.cpp +++ b/test/numerics/rand/rand.eng/rand.eng.lcong/seed_sseq.pass.cpp @@ -28,4 +28,12 @@ int main() e1.seed(sseq); assert(e1 == e2); } + { + unsigned a[] = {3, 5, 7, 9, 11}; + std::seed_seq sseq(a, a+5); + typedef std::linear_congruential_engine E; + E e1(4309005589); + E e2(sseq); + assert(e1 == e2); + } }