//===----------------------------------------------------------------------===// // // 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 shuffle_order_engine // result_type operator()(); #include #include template class rand1 { public: // types typedef UIntType result_type; private: result_type x_; static_assert(Min < Max, "rand1 invalid parameters"); public: #ifdef _LIBCPP_HAS_NO_CONSTEXPR // Workaround for lack of constexpr in C++03 static const result_type _Min = Min; static const result_type _Max = Max; #endif static _LIBCPP_CONSTEXPR result_type min() {return Min;} static _LIBCPP_CONSTEXPR result_type max() {return Max;} explicit rand1(result_type sd = Min) : x_(sd) { if (x_ > Max) x_ = Max; } result_type operator()() { result_type r = x_; if (x_ < Max) ++x_; else x_ = Min; return r; } }; void test1() { typedef std::knuth_b E; E e; assert(e() == 152607844u); } void test2() { typedef rand1 E0; typedef std::shuffle_order_engine E; E e; e.discard(400); assert(e() == 501); } void test3() { typedef rand1 E0; typedef std::shuffle_order_engine E; E e; e.discard(400); assert(e() == 500); } int main() { test1(); test2(); test3(); }