MCPcopy Create free account
hub / github.com/Kistler-Group/sdbus-cpp / createRandomString

Function createRandomString

tests/perftests/server.cpp:83–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81};
82
83std::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//-----------------------------------------

Callers 1

sendDataSignalsMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected