Initial submit
This commit is contained in:
33
tools.cpp
33
tools.cpp
@@ -1,12 +1,33 @@
|
||||
#include "tools.h"
|
||||
|
||||
namespace Yp {
|
||||
namespace Lib {
|
||||
#include <random>
|
||||
#include <string>
|
||||
|
||||
Tools::Tools()
|
||||
{
|
||||
namespace Yc {
|
||||
namespace Lib {
|
||||
|
||||
}
|
||||
Tools::Tools() {
|
||||
|
||||
} // namespace Lib
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user