Jlm
strfmt.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Nico Reißmann <nico.reissmann@gmail.com>
3  * Copyright 2025 Håvard Krogstie <krogstie.havard@gmail.com>
4  * See COPYING for terms of redistribution.
5  */
6 
7 #include <jlm/util/strfmt.hpp>
8 
9 #include <random>
10 
11 namespace jlm::util
12 {
13 
14 std::string
15 CreateRandomAlphanumericString(std::size_t length)
16 {
17  const std::string characterSet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
18 
19  std::random_device random_device;
20  std::mt19937 generator(random_device());
21  std::uniform_int_distribution<> distribution(0, characterSet.size() - 1);
22 
23  std::string result;
24  for (std::size_t i = 0; i < length; ++i)
25  {
26  result += characterSet[distribution(generator)];
27  }
28 
29  return result;
30 }
31 
32 }
std::string CreateRandomAlphanumericString(std::size_t length)
Definition: strfmt.cpp:15