1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 // template <class UIntType, UIntType a, UIntType c, UIntType m>
12 // class linear_congruential_engine;
14 // result_type operator()();
19 #include "test_macros.h"
23 typedef unsigned long long T
;
25 // m might overflow, but the overflow is OK so it shouldn't use schrage's algorithm
26 typedef std::linear_congruential_engine
<T
, 25214903917ull, 1, (1ull<<48)> E1
;
28 // make sure the right algorithm was used
29 assert(e1() == 25214903918);
30 assert(e1() == 205774354444503);
31 assert(e1() == 158051849450892);
32 // make sure result is in bounds
33 assert(e1() < (1ull<<48));
34 assert(e1() < (1ull<<48));
35 assert(e1() < (1ull<<48));
36 assert(e1() < (1ull<<48));
37 assert(e1() < (1ull<<48));
39 // m might overflow. The overflow is not OK and result will be in bounds
40 // so we should use shrage's algorithm
41 typedef std::linear_congruential_engine
<T
, (1ull<<2), 0, (1ull<<63) + 1> E2
;
43 // make sure shrage's algorithm is used (it would be 0s otherwise)
47 // make sure result is in bounds
48 assert(e2() < (1ull<<48) + 1);
49 assert(e2() < (1ull<<48) + 1);
50 assert(e2() < (1ull<<48) + 1);
51 assert(e2() < (1ull<<48) + 1);
52 assert(e2() < (1ull<<48) + 1);
54 // m will not overflow so we should not use shrage's algorithm
55 typedef std::linear_congruential_engine
<T
, 1ull, 1, (1ull<<48)> E3
;
57 // make sure the correct algorithm was used
61 // make sure result is in bounds
62 assert(e3() < (1ull<<48));
63 assert(e3() < (1ull<<48));
64 assert(e3() < (1ull<<48));
65 assert(e3() < (1ull<<48));
66 assert(e2() < (1ull<<48));