]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/experimental/random/randint.cc
1 // { dg-do run { target c++14 } }
2 // { dg-require-effective-target tls_runtime }
3 // { dg-add-options tls }
5 // Copyright (C) 2015-2016 Free Software Foundation, Inc.
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a moved_to of the GNU General Public License along
19 // with this library; see the file COPYING3. If not see
20 // <http://www.gnu.org/licenses/>.
22 #include <experimental/random>
23 #include <testsuite_hooks.h>
28 for (int i
= 0; i
< 100; ++i
)
30 const int n
= std::experimental::randint(-10, i
);
31 VERIFY( -10 <= n
&& n
<= i
);
34 std::experimental::reseed(99u);
36 std::experimental::randint(0, 100),
37 std::experimental::randint(0, 100),
38 std::experimental::randint(0, 100),
39 std::experimental::randint(0, 100),
40 std::experimental::randint(0, 100)
42 std::experimental::reseed(99u);
44 std::experimental::randint(0, 100),
45 std::experimental::randint(0, 100),
46 std::experimental::randint(0, 100),
47 std::experimental::randint(0, 100),
48 std::experimental::randint(0, 100)
50 for (int i
= 0; i
< 5; ++i
)
51 VERIFY( n1
[i
] == n2
[i
] );
53 std::experimental::reseed();
55 std::experimental::randint(0, 100),
56 std::experimental::randint(0, 100),
57 std::experimental::randint(0, 100)
59 VERIFY( !(n3
[0] == n1
[0] && n3
[1] == n1
[1] && n3
[2] == n1
[2]) );
65 auto check
= [](auto v
) {
66 auto n
= std::experimental::randint(decltype(v
)(0), v
);
67 static_assert(std::is_same
<decltype(n
), decltype(v
)>::value
,
68 "return type is correct");
69 VERIFY(0 <= n
&& n
<= v
);
75 check( (unsigned short)10 );