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