example3_checking_entropy.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <random>
#include <iomanip>

int main() {
    std::random_device rd;

    std::cout << "Entropy of random_device: " << rd.entropy() << std::endl;

    if (rd.entropy() > 0) {
        std::cout << "random_device is non-deterministic" << std::endl;
    } else {
        std::cout << "random_device might be deterministic" << std::endl;
    }

    // Generate and print a random number in hexadecimal
    std::cout << "Random number (hex): " 
              << std::hex << std::setw(8) << std::setfill('0') 
              << rd() << std::endl;

    return 0;
}
Back to std_random_device