25 #include <openssl/err.h>
26 #include <openssl/rand.h>
49 if (RAND_bytes(buf.data(), buf.size()) != 1) {
50 NDN_THROW(std::runtime_error(
"Failed to generate random bytes (error code " +
58 thread_local std::mt19937 rng = [] {
59 std::random_device rd;
61 std::seed_seq seeds{rd(), rd(), rd(), rd(), rd(), rd(), rd(), rd()};
62 return std::mt19937{seeds};
70 thread_local std::uniform_int_distribution<uint32_t> distribution;
77 thread_local std::uniform_int_distribution<uint64_t> distribution;
std::string to_string(const errinfo_stacktrace &x)
uint32_t generateSecureWord32()
Generate a cryptographically secure random integer in the range [0, 2^32).
uint32_t generateWord32()
Generate a non-cryptographically-secure random integer in the range [0, 2^32).
void generateSecureBytes(span< uint8_t > buf)
Fill buffer with cryptographically secure random bytes.
std::mt19937 RandomNumberEngine
uint64_t generateSecureWord64()
Generate a cryptographically secure random integer in the range [0, 2^64).
uint64_t generateWord64()
Generate a non-cryptographically-secure random integer in the range [0, 2^64).
RandomNumberEngine & getRandomNumberEngine()
Returns a reference to a thread-local instance of a properly seeded PRNG.