| 9 | #include <string> |
| 10 | |
| 11 | inline 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 | |
| 36 | struct TemporaryFile |
| 37 | { |
no test coverage detected