MCPcopy Create free account
hub / github.com/davisking/dlib / get_random_string

Method get_random_string

dlib/http_client/http_client.cpp:207–225  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

205// ----------------------------------------------------------------------------------------
206
207 std::string http_client::get_random_string( size_t length ) const
208 {
209 static bool has_seeded(false);
210 static std::string allowed_chars("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
211
212 if ( !has_seeded )
213 {
214 has_seeded = true;
215 ::srand( static_cast<unsigned int>(::time(NULL)) );
216 }
217
218 std::string retVal; retVal.reserve(length);
219 while ( retVal.size() < length )
220 {
221 retVal += allowed_chars[(rand() % allowed_chars.size())];
222 }
223
224 return retVal;
225 }
226
227// ----------------------------------------------------------------------------------------
228

Callers

nothing calls this directly

Calls 3

randClass · 0.50
reserveMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected