idfxx 1.0.0
Modern C++23 components for ESP-IDF
Loading...
Searching...
No Matches
random.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Chris Leishman
3
4#pragma once
5
30#include <cstdint>
31#include <esp_random.h>
32#include <limits>
33#include <span>
34
35namespace idfxx {
36
46 return esp_random();
47}
48
54inline void fill_random(std::span<uint8_t> buf) noexcept {
55 esp_fill_random(buf.data(), buf.size());
56}
57
63inline void fill_random(std::span<std::byte> buf) noexcept {
64 esp_fill_random(buf.data(), buf.size());
65}
66
81public:
84
90 static constexpr result_type min() noexcept { return std::numeric_limits<result_type>::min(); }
91
97 static constexpr result_type max() noexcept { return std::numeric_limits<result_type>::max(); }
98
105};
106
// end of idfxx_core_random // end of idfxx_core
109
110} // namespace idfxx
Hardware random number generator satisfying UniformRandomBitGenerator.
Definition random.hpp:80
static constexpr result_type min() noexcept
Returns the minimum value that can be generated.
Definition random.hpp:90
uint32_t result_type
The type of random values produced.
Definition random.hpp:83
static constexpr result_type max() noexcept
Returns the maximum value that can be generated.
Definition random.hpp:97
result_type operator()() noexcept
Generates a random value.
Definition random.hpp:104
void fill_random(std::span< uint8_t > buf) noexcept
Fills a buffer with hardware-generated random bytes.
Definition random.hpp:54
uint32_t random() noexcept
Returns a hardware-generated random 32-bit value.
Definition random.hpp:45
std::expected< T, std::error_code > result
result type wrapping a value or error code.
Definition error.hpp:120