ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
Common.cpp
Go to the documentation of this file.
1 // SPDX-License-Identifier: BSL-1.0
2 // Copyright (c) 2020 PTC Inc.
3 
4 #include "Common.h"
5 
6 #include <random>
7 
8 namespace e57
9 {
10 
11  std::string generateRandomGUID()
12  {
13  static constexpr const char UUID_CHARS[] = "0123456789ABCDEF";
14  static std::random_device rd;
15  static std::mt19937 gen( rd() );
16  static std::uniform_int_distribution<> dis( 0, 15 /* number of chars in UUID_CHARS */ );
17 
18  std::string uuid( 38, ' ' );
19 
20  uuid[0] = '{';
21  uuid[9] = '-';
22  uuid[14] = '-';
23  uuid[19] = '-';
24  uuid[24] = '-';
25  uuid[37] = '}';
26 
27  uuid[15] = '4';
28 
29  for ( int i = 1; i < 37; ++i )
30  {
31  if ( i != 9 && i != 14 && i != 19 && i != 24 && i != 15 )
32  {
33  uuid[i] = UUID_CHARS[dis( gen )];
34  }
35  }
36  return uuid;
37  }
38 
39 } // end namespace e57
std::string generateRandomGUID()
generates a new random GUID
Definition: Common.cpp:11