1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <random>
11
12// template<class Engine, size_t k>
13// class shuffle_order_engine
14
15// result_type operator()();
16
17#include <random>
18#include <cassert>
19
20template <class UIntType, UIntType Min, UIntType Max>
21class rand1
22{
23public:
24    // types
25    typedef UIntType result_type;
26
27private:
28    result_type x_;
29
30    static_assert(Min < Max, "rand1 invalid parameters");
31public:
32
33#ifdef _LIBCPP_HAS_NO_CONSTEXPR
34    // Workaround for lack of constexpr in C++03
35    static const result_type _Min = Min;
36    static const result_type _Max = Max;
37#endif
38
39    static _LIBCPP_CONSTEXPR result_type min() {return Min;}
40    static _LIBCPP_CONSTEXPR result_type max() {return Max;}
41
42    explicit rand1(result_type sd = Min) : x_(sd)
43    {
44        if (x_ > Max)
45            x_ = Max;
46    }
47
48    result_type operator()()
49    {
50        result_type r = x_;
51        if (x_ < Max)
52            ++x_;
53        else
54            x_ = Min;
55        return r;
56    }
57};
58
59void
60test1()
61{
62   typedef std::knuth_b E;
63
64    E e;
65    assert(e() == 152607844u);
66}
67
68void
69test2()
70{
71    typedef rand1<unsigned long long, 0, 0xFFFFFFFFFFFFFFFFull> E0;
72    typedef std::shuffle_order_engine<E0, 101> E;
73    E e;
74    e.discard(400);
75    assert(e() == 501);
76}
77
78void
79test3()
80{
81    typedef rand1<unsigned long long, 0, 0xFFFFFFFFFFFFFFFFull> E0;
82    typedef std::shuffle_order_engine<E0, 100> E;
83    E e;
84    e.discard(400);
85    assert(e() == 500);
86}
87
88int main()
89{
90    test1();
91    test2();
92    test3();
93}
94