commit 7d241a5a21afc25ba5d0c8f44b86a259ee40d0ea Author: Redacted Date: Sat Jun 1 23:43:44 2024 -0400 Initial commit diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..e5fedc8 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.18) +project(uuid) + +set(CMAKE_CXX_STANDARD 20) + +file(GLOB_RECURSE HEADERS "include/*.h") +file(GLOB_RECURSE SOURCES "src/*.cpp") + +include_directories("include") + +add_library(uuid SHARED ${SOURCES} ${HEADERS}) +add_executable(uuidtest main.cpp) +set_target_properties(uuid PROPERTIES LINKER_LANGUAGE CXX) +target_link_libraries(uuidtest PUBLIC uuid) \ No newline at end of file diff --git a/include/uuid/uuid.h b/include/uuid/uuid.h new file mode 100644 index 0000000..b44489f --- /dev/null +++ b/include/uuid/uuid.h @@ -0,0 +1,7 @@ +#pragma once +#include + +namespace UUID { + int dice(int min, int max); + std::string generateUUID(unsigned int length); +} \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..8897e89 --- /dev/null +++ b/main.cpp @@ -0,0 +1,6 @@ +#include +#include +int main() { + std::cout << UUID::generateUUID(16) << std::endl; + std::cout << UUID::dice(0, 65535) << std::endl; +} \ No newline at end of file diff --git a/src/uuid.cpp b/src/uuid.cpp new file mode 100644 index 0000000..4c2fdf2 --- /dev/null +++ b/src/uuid.cpp @@ -0,0 +1,24 @@ +#include +#include +#include + +std::random_device randomDevice; +std::mt19937 rng(randomDevice()); + +std::array characters = { + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '%', '!' +}; + +int UUID::dice(int min, int max) { + std::uniform_int_distribution<> generate(min, max); + return generate(rng); +} + +std::string UUID::generateUUID(const unsigned int length) { + std::string result; + for (int i = 0; i < length; i++) + result.push_back(characters[UUID::dice(0, 63)]); + return result; +}