Util.cpp 516 B

12345678910111213141516171819202122232425
  1. #include <algorithm>
  2. #include "Util.h"
  3. namespace PresenceDetection {
  4. namespace Util {
  5. std::string CreateRandomString(size_t length)
  6. {
  7. auto randchar = []() -> char
  8. {
  9. const char charset[] =
  10. "0123456789"
  11. "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  12. "abcdefghijklmnopqrstuvwxyz";
  13. const size_t max_index = (sizeof(charset) - 1);
  14. return charset[ rand() % max_index ];
  15. };
  16. std::string str(length,0);
  17. std::generate_n(str.begin(), length, randchar);
  18. return str;
  19. }
  20. } // namespace Util
  21. } // namespace PresenceDetection