xref: /llvm-project/libcxx/test/std/numerics/rand/rand.eng/rand.eng.lcong/discard.pass.cpp (revision 2df59c50688c122bbcae7467d3eaf862c3ea3088)
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // <random>
10 
11 // template <class UIntType, UIntType a, UIntType c, UIntType m>
12 //   class linear_congruential_engine;
13 
14 // void discard(unsigned long long z);
15 
16 #include <random>
17 #include <cassert>
18 
19 template <class T>
20 void
21 rand0()
22 {
23     typedef std::linear_congruential_engine<T, 16807, 0, 2147483647> E;
24     E e;
25     e.discard(9999);
26     assert(e() == 1043618065);
27 }
28 
29 template <class T>
30 void
31 rand()
32 {
33     typedef std::linear_congruential_engine<T, 48271, 0, 2147483647> E;
34     E e;
35     e.discard(9999);
36     assert(e() == 399268537);
37 }
38 
39 template <class T>
40 void
41 other()
42 {
43     typedef std::linear_congruential_engine<T, 48271, 123465789, 2147483647> E;
44     E e1;
45     E e2;
46     assert(e1 == e2);
47     e1.discard(1);
48     assert(e1 != e2);
49     (void)e2();
50     assert(e1 == e2);
51     e1.discard(3);
52     assert(e1 != e2);
53     (void)e2();
54     (void)e2();
55     (void)e2();
56     assert(e1 == e2);
57 }
58 
59 int main(int, char**)
60 {
61     rand0<unsigned int>();
62     rand0<unsigned long>();
63     rand0<unsigned long long>();
64 
65     rand<unsigned int>();
66     rand<unsigned long>();
67     rand<unsigned long long>();
68 
69     other<unsigned int>();
70     other<unsigned long>();
71     other<unsigned long long>();
72 
73   return 0;
74 }
75