34 lines
814 B
C++
34 lines
814 B
C++
#include "tools.h"
|
|
|
|
#include <random>
|
|
#include <string>
|
|
|
|
namespace Yc {
|
|
namespace Lib {
|
|
|
|
Tools::Tools() {
|
|
|
|
}
|
|
|
|
std::string Tools::generateRandomString(size_t length) {
|
|
std::string choices(
|
|
"0123456789"
|
|
"`~!@#$%^&*()-_=+[{]}|\\:;<,>./?"
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
|
);
|
|
|
|
std::random_device random;
|
|
std::mt19937 generator(random());
|
|
std::uniform_int_distribution<size_t> distribution(0, choices.size());
|
|
|
|
std::string result(length, '0');
|
|
for (size_t i = 0; i < length; ++i) {
|
|
result[i] = choices[distribution(generator)];
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
} // namespace Lib
|
|
} // namespace Yp
|