| 89 | }; |
| 90 | |
| 91 | std::string createRandomString(size_t length) |
| 92 | { |
| 93 | auto randchar = []() -> char |
| 94 | { |
| 95 | const char charset[] = |
| 96 | "0123456789" |
| 97 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 98 | "abcdefghijklmnopqrstuvwxyz"; |
| 99 | const size_t max_index = (sizeof(charset) - 1); |
| 100 | return charset[ random() % max_index ]; |
| 101 | }; |
| 102 | |
| 103 | struct timespec ts{}; |
| 104 | (void)timespec_get(&ts, TIME_UTC); |
| 105 | srandom(ts.tv_nsec ^ ts.tv_sec); /* Seed the PRNG */ |
| 106 | |
| 107 | std::string str(length, 0); |
| 108 | std::generate_n(str.begin(), length, randchar); |
| 109 | return str; |
| 110 | } |
| 111 | |
| 112 | |
| 113 | //----------------------------------------- |