pinocchio  UNKNOWN
string-generator.hpp
1 //
2 // Copyright (c) 2016 CNRS
3 //
4 // This file is part of Pinocchio
5 // Pinocchio is free software: you can redistribute it
6 // and/or modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation, either version
8 // 3 of the License, or (at your option) any later version.
9 //
10 // Pinocchio is distributed in the hope that it will be
11 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Lesser Public License for more details. You should have
14 // received a copy of the GNU Lesser General Public License along with
15 // Pinocchio If not, see
16 // <http://www.gnu.org/licenses/>.
17 
18 #ifndef __se3_string_generator_hpp__
19 #define __se3_string_generator_hpp__
20 
21 #include <string>
22 #include <cstdlib>
23 
24 namespace se3
25 {
26 
34  inline std::string randomStringGenerator(const int len)
35  {
36  std::string res;
37  static const char alphanum[] =
38  "0123456789"
39  "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
40  "abcdefghijklmnopqrstuvwxyz";
41 
42  for (int i=0; i<len;++i)
43  res += alphanum[((size_t)std::rand() % (sizeof(alphanum) - 1))];
44  return res;
45  }
46 }
47 
48 #endif // __se3_string_generator_hpp__
std::string randomStringGenerator(const int len)
Generate a random string composed of alphanumeric symbols of a given length.