From dc67f5661b59029624b21be76a5962a7af40dd1b Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Thu, 4 Feb 2021 06:16:10 +0100 Subject: [PATCH] Fixed bug --- include/esprandom.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/esprandom.h b/include/esprandom.h index c4e72d1..eac63c3 100644 --- a/include/esprandom.h +++ b/include/esprandom.h @@ -4,6 +4,7 @@ #include #include #include +#include // esp-idf includes #include @@ -25,14 +26,14 @@ public: std::string randomString(std::size_t length) { - static constexpr const char chars[] = + static constexpr auto chars = "0123456789" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"; auto rng = esp_random_device{}; - auto dist = std::uniform_int_distribution{{}, std::size(chars) - 1}; + auto dist = std::uniform_int_distribution{{}, std::strlen(chars) - 1}; auto result = std::string(length, '\0'); std::generate_n(std::begin(result), length, [&]() { return chars[dist(rng)]; });