| 1 |
// { dg-do run { target c++11 } } |
| 2 |
|
| 3 |
#include <random> |
| 4 |
#include <limits> |
| 5 |
#include <testsuite_hooks.h> |
| 6 |
#include <testsuite_random.h> |
| 7 |
|
| 8 |
void |
| 9 |
test01() |
| 10 |
{ |
| 11 |
for (auto token : { "mt19937", "prng", "rand_s" }) |
| 12 |
if (__gnu_test::random_device_available(token)) |
| 13 |
VERIFY( std::random_device(token).entropy() == 0.0 ); |
| 14 |
|
| 15 |
using result_type = std::random_device::result_type; |
| 16 |
const double max = std::numeric_limits<result_type>::digits; |
| 17 |
|
| 18 |
for (auto token : { "/dev/random", "/dev/urandom" }) |
| 19 |
if (__gnu_test::random_device_available(token)) |
| 20 |
{ |
| 21 |
const double entropy = std::random_device(token).entropy(); |
| 22 |
VERIFY( entropy >= 0.0 ); |
| 23 |
VERIFY( entropy <= max ); |
| 24 |
} |
| 25 |
|
| 26 |
for (auto token : { "rdrand", "rdseed", "darn", "hw" }) |
| 27 |
if (__gnu_test::random_device_available(token)) |
| 28 |
{ |
| 29 |
const double entropy = std::random_device(token).entropy(); |
| 30 |
VERIFY( entropy == max ); |
| 31 |
} |
| 32 |
|
| 33 |
for (auto token : { "getentropy", "arc4random" }) |
| 34 |
if (__gnu_test::random_device_available(token)) |
| 35 |
{ |
| 36 |
const double entropy = std::random_device(token).entropy(); |
| 37 |
VERIFY( entropy == max ); |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
int |
| 42 |
main() |
| 43 |
{ |
| 44 |
test01(); |
| 45 |
} |