IgANet
IGAnets - Isogeometric Analysis Networks
Loading...
Searching...
No Matches
uuid.hpp
Go to the documentation of this file.
1
15#pragma once
16
17#include <random>
18#include <sstream>
19
20namespace iganet::utils {
21
22class uuid {
23public:
28 static std::string create() {
29 std::stringstream hexstream;
30 hexstream << uuid::random_hex(4) << "-" << uuid::random_hex(2) << "-"
31 << uuid::random_hex(2) << "-" << uuid::random_hex(2) << "-"
32 << uuid::random_hex(6);
33 return hexstream.str();
34 }
35
36private:
42 static std::string random_hex(const unsigned int len) {
43 std::stringstream ss;
44 for (auto i = 0; i < len; i++) {
45 const auto rc = random_char();
46 std::stringstream hexstream;
47 hexstream << std::hex << rc;
48 auto hex = hexstream.str();
49 ss << (hex.length() < 2 ? '0' + hex : hex);
50 }
51 return ss.str();
52 }
53
57 static unsigned int random_char() {
58 std::random_device rd;
59 std::mt19937 gen(rd());
60 std::uniform_int_distribution<> dis(0, 255);
61 return dis(gen);
62 }
63};
64
65} // namespace iganet::utils
Definition uuid.hpp:22
static unsigned int random_char()
Generates a safe pseudo-random character.
Definition uuid.hpp:57
static std::string create()
Generates an uuid string in the form b9317db-02a2-4882-9b94-d1e1defe8c56.
Definition uuid.hpp:28
static std::string random_hex(const unsigned int len)
Generates a string of random hex chars.
Definition uuid.hpp:42
Definition blocktensor.hpp:24