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

Function createRandomString

tests/perftests/client.cpp:91–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89};
90
91std::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//-----------------------------------------

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected