]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/26_numerics/random/random_device/94087.cc
1 // Copyright (C) 2020-2024 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
19 // { dg-options "-pthread" }
20 // { dg-require-effective-target c++11 }
21 // { dg-require-effective-target pthread }
22 // { dg-require-gthreads "" }
28 #include <testsuite_random.h>
30 using __gnu_test::random_device_available
;
32 void read_random_device(const char* token
, int iterations
)
34 std::random_device
dev(token
);
35 for (int i
= 0; i
!= iterations
; ++i
)
40 std::thread workers
[8];
42 // N.B. don't test /dev/random as it might block, and /dev/urandom
43 // "can incur an appreciable delay when requesting large amounts of data".
44 for (const char* dev
: { "default", "rdrand", "rdseed", "rand_s" })
46 if (random_device_available(dev
))
48 for (auto& w
: workers
)
49 w
= std::thread
{read_random_device
, dev
, 1000};
50 for (auto& w
: workers
)
54 std::printf("random_device(\"%s\") not available\n", dev
);