31 lines
538 B
C
31 lines
538 B
C
#include "random.h"
|
|
#include "esp_random.h"
|
|
|
|
void rand_str(size_t len, char *dest)
|
|
{
|
|
for (size_t i = 0; i < len; i++)
|
|
{
|
|
uint32_t v = esp_random() % (26 * 2 + 10);
|
|
|
|
// Upper case letter
|
|
if (v < 26)
|
|
{
|
|
dest[i] = 65 + v;
|
|
continue;
|
|
}
|
|
v -= 26;
|
|
|
|
// Lower case letter
|
|
if (v < 26)
|
|
{
|
|
dest[i] = 97 + v;
|
|
continue;
|
|
}
|
|
v -= 26;
|
|
|
|
// Digit
|
|
dest[i] = 48 + (v % 10);
|
|
}
|
|
|
|
dest[len] = '\0';
|
|
} |