xref: /llvm-project/libcxx/test/std/numerics/rand/rand.eng/rand.eng.sub/ctor_sseq.pass.cpp (revision a7f9895cc18995549c7facb96e72718da282a864)
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, size_t w, size_t s, size_t r>
12 // class subtract_with_carry_engine;
13 
14 // template<class Sseq> explicit subtract_with_carry_engine(Sseq& q);
15 
16 // Serializing/deserializing the state of the RNG requires iostreams
17 // UNSUPPORTED: no-localization
18 
19 #include <random>
20 #include <sstream>
21 #include <cassert>
22 
23 #include "test_macros.h"
24 
25 void
test1()26 test1()
27 {
28     const char* a = "13604817 711567 9760686 13278398 3323440 175548 5553651 "
29     "3028863 10748297 2216688 275779 14778841 14438394 9483441 4229545 "
30     "14657301 12636508 15978210 1653340 1718567 9272421 14302862 7940348 "
31     "889045 0";
32     unsigned as[] = {3, 5, 7};
33     std::seed_seq sseq(as, as+3);
34     std::ranlux24_base e1(sseq);
35     std::ostringstream os;
36     os << e1;
37     assert(os.str() == a);
38 }
39 
40 void
test2()41 test2()
42 {
43     const char* a = "241408498702289 172342669275054 191026374555184 "
44     "61020585639411 231929771458953 142769679250755 198672786411514 "
45     "183712717244841 227473912549724 62843577252444 68782400568421 "
46     "159248704678140 0";
47     unsigned as[] = {3, 5, 7};
48     std::seed_seq sseq(as, as+3);
49     std::ranlux48_base e1(sseq);
50     std::ostringstream os;
51     os << e1;
52     assert(os.str() == a);
53 }
54 
main(int,char **)55 int main(int, char**)
56 {
57     test1();
58     test2();
59 
60   return 0;
61 }
62