MCPcopy Create free account
hub / github.com/Project-OSRM/osrm-backend / random_string

Function random_string

unit_tests/common/temporary_file.hpp:11–34  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9#include <string>
10
11inline std::string random_string(std::string::size_type length)
12{
13 static auto &chrs = "0123456789"
14 "abcdefghijklmnopqrstuvwxyz"
15 "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
16
17 // Mix in the address of a local static as a per-process salt (ASLR)
18 // to avoid filename collisions when tests run in parallel, while
19 // preserving deterministic sequences within a single process.
20 thread_local static std::mt19937 rg{
21 osrm::test::getTestRandomSeed() ^
22 static_cast<unsigned>(reinterpret_cast<std::uintptr_t>(&chrs))};
23 thread_local static std::uniform_int_distribution<std::string::size_type> pick(
24 0, sizeof(chrs) - 2);
25
26 std::string s;
27 s.reserve(length);
28
29 while (length--)
30 {
31 s += chrs[pick(rg)];
32 }
33 return s;
34}
35
36struct TemporaryFile
37{

Callers 1

TemporaryFileMethod · 0.85

Calls 2

getTestRandomSeedFunction · 0.85
reserveMethod · 0.45

Tested by

no test coverage detected