Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / numerics / rand / rand.eng / rand.eng.lcong / discard.pass.cpp
bloba60bd261af973a719895141eb2341b5a79ebc4ad
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 //===----------------------------------------------------------------------===//
9 // <random>
11 // template <class UIntType, UIntType a, UIntType c, UIntType m>
12 // class linear_congruential_engine;
14 // void discard(unsigned long long z);
16 #include <random>
17 #include <cassert>
19 #include "test_macros.h"
21 template <class T>
22 void
23 rand0()
25 typedef std::linear_congruential_engine<T, 16807, 0, 2147483647> E;
26 E e;
27 e.discard(9999);
28 assert(e() == 1043618065);
31 template <class T>
32 void
33 rand()
35 typedef std::linear_congruential_engine<T, 48271, 0, 2147483647> E;
36 E e;
37 e.discard(9999);
38 assert(e() == 399268537);
41 template <class T>
42 void
43 other()
45 typedef std::linear_congruential_engine<T, 48271, 123465789, 2147483647> E;
46 E e1;
47 E e2;
48 assert(e1 == e2);
49 e1.discard(1);
50 assert(e1 != e2);
51 (void)e2();
52 assert(e1 == e2);
53 e1.discard(3);
54 assert(e1 != e2);
55 (void)e2();
56 (void)e2();
57 (void)e2();
58 assert(e1 == e2);
61 int main(int, char**)
63 rand0<unsigned int>();
64 rand0<unsigned long>();
65 rand0<unsigned long long>();
67 rand<unsigned int>();
68 rand<unsigned long>();
69 rand<unsigned long long>();
71 other<unsigned int>();
72 other<unsigned long>();
73 other<unsigned long long>();
75 return 0;