• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 UIntType, UIntType a, UIntType c, UIntType m>
13 //   class linear_congruential_engine;
14 
15 // void discard(unsigned long long z);
16 
17 #include <random>
18 #include <cassert>
19 
20 template <class T>
21 void
rand0()22 rand0()
23 {
24     typedef std::linear_congruential_engine<T, 16807, 0, 2147483647> E;
25     E e;
26     e.discard(9999);
27     assert(e() == 1043618065);
28 }
29 
30 template <class T>
31 void
rand()32 rand()
33 {
34     typedef std::linear_congruential_engine<T, 48271, 0, 2147483647> E;
35     E e;
36     e.discard(9999);
37     assert(e() == 399268537);
38 }
39 
40 template <class T>
41 void
other()42 other()
43 {
44     typedef std::linear_congruential_engine<T, 48271, 123465789, 2147483647> E;
45     E e1;
46     E e2;
47     assert(e1 == e2);
48     e1.discard(1);
49     assert(e1 != e2);
50     e2();
51     assert(e1 == e2);
52     e1.discard(3);
53     assert(e1 != e2);
54     e2();
55     e2();
56     e2();
57     assert(e1 == e2);
58 }
59 
main()60 int main()
61 {
62     rand0<unsigned int>();
63     rand0<unsigned long>();
64     rand0<unsigned long long>();
65 
66     rand<unsigned int>();
67     rand<unsigned long>();
68     rand<unsigned long long>();
69 
70     other<unsigned int>();
71     other<unsigned long>();
72     other<unsigned long long>();
73 }
74