Fixed bug
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
#include <limits>
|
#include <limits>
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
// esp-idf includes
|
// esp-idf includes
|
||||||
#include <esp_system.h>
|
#include <esp_system.h>
|
||||||
@@ -25,14 +26,14 @@ public:
|
|||||||
|
|
||||||
std::string randomString(std::size_t length)
|
std::string randomString(std::size_t length)
|
||||||
{
|
{
|
||||||
static constexpr const char chars[] =
|
static constexpr auto chars =
|
||||||
"0123456789"
|
"0123456789"
|
||||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
"abcdefghijklmnopqrstuvwxyz";
|
"abcdefghijklmnopqrstuvwxyz";
|
||||||
|
|
||||||
auto rng = esp_random_device{};
|
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');
|
auto result = std::string(length, '\0');
|
||||||
std::generate_n(std::begin(result), length, [&]() { return chars[dist(rng)]; });
|
std::generate_n(std::begin(result), length, [&]() { return chars[dist(rng)]; });
|
||||||
|
Reference in New Issue
Block a user