]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/26_numerics/random/random_device/cons/token.cc
1 // { dg-do run { target c++11 } }
2 // { dg-require-cstdint "" }
4 // 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
6 // Copyright (C) 2008-2024 Free Software Foundation, Inc.
8 // This file is part of the GNU ISO C++ Library. This library is free
9 // software; you can redistribute it and/or modify it under the
10 // terms of the GNU General Public License as published by the
11 // Free Software Foundation; either version 3, or (at your option)
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
19 // You should have received a copy of the GNU General Public License along
20 // with this library; see the file COPYING3. If not see
21 // <http://www.gnu.org/licenses/>.
23 // C++11 26.5.6 class random_device [rand.device]
28 #include <testsuite_hooks.h>
29 #include <testsuite_random.h>
34 std::random_device
x("default");
35 using result_type
= std::random_device::result_type
;
36 VERIFY( x
.min() == std::numeric_limits
<result_type
>::min() );
37 VERIFY( x
.max() == std::numeric_limits
<result_type
>::max() );
43 #ifdef _GLIBCXX_USE_DEV_RANDOM
44 std::random_device
x1("/dev/urandom");
45 std::random_device
x2("/dev/random");
46 VERIFY( x1() != x2() || x1() != x2() );
53 // At least one of these tokens should be valid.
54 const std::string tokens
[] = {
55 "rdseed", "rdrand", "darn",
56 "rand_s", "/dev/urandom", "/dev/random",
57 "getentropy", "arc4random",
61 for (const std::string
& token
: tokens
)
63 std::printf("checking std::random_device(\"%s\"):\t", token
.c_str());
64 if (__gnu_test::random_device_available(token
))
78 if (__gnu_test::random_device_available("mt19937"))
80 std::random_device
x("mt19937");
81 std::random_device::result_type xval
= x();
83 // If "mt19937" is a valid token then numeric seeds should be too.
84 std::random_device
x1("0");
85 std::random_device
x2("1234");
86 std::random_device
x3("0xc0fefe");
87 VERIFY( xval
!= x1() );
88 VERIFY( x2() != x3() );