idfxx 1.0.0
Modern C++23 components for ESP-IDF
Loading...
Searching...
No Matches
Random Numbers

True random number generation using the hardware RNG. More...

Namespaces

namespace  idfxx
 

Classes

class  idfxx::random_device
 Hardware random number generator satisfying UniformRandomBitGenerator. More...
 

Functions

uint32_t idfxx::random () noexcept
 Returns a hardware-generated random 32-bit value.
 
void idfxx::fill_random (std::span< uint8_t > buf) noexcept
 Fills a buffer with hardware-generated random bytes.
 
void idfxx::fill_random (std::span< std::byte > buf) noexcept
 Fills a buffer with hardware-generated random bytes.
 

Detailed Description

True random number generation using the hardware RNG.

Provides free functions and a C++ UniformRandomBitGenerator class backed by the hardware random number generator.

uint32_t val = idfxx::random();
std::uniform_int_distribution<int> dist(1, 100);
int n = dist(rng);
Hardware random number generator satisfying UniformRandomBitGenerator.
Definition random.hpp:80
uint32_t random() noexcept
Returns a hardware-generated random 32-bit value.
Definition random.hpp:45

Function Documentation

◆ fill_random() [1/2]

void idfxx::fill_random ( std::span< std::byte >  buf)
inlinenoexcept

Fills a buffer with hardware-generated random bytes.

Parameters
bufThe buffer to fill with random data.

Definition at line 63 of file random.hpp.

◆ fill_random() [2/2]

void idfxx::fill_random ( std::span< uint8_t buf)
inlinenoexcept

Fills a buffer with hardware-generated random bytes.

Parameters
bufThe buffer to fill with random data.

Definition at line 54 of file random.hpp.

◆ random()

uint32_t idfxx::random ( )
inlinenoexcept

Returns a hardware-generated random 32-bit value.

Uses the true hardware random number generator when RF subsystem is active, or a pseudo-random source otherwise.

Returns
A random 32-bit unsigned integer.

Definition at line 45 of file random.hpp.