C++ 产生UUID
原创
©著作权归作者所有:来自51CTO博客作者wuyi_all_in的原创作品,请联系作者获取转载授权,否则将追究法律责任
#include <iostream>
#include <sstream>
#include <iomanip>
#include <chrono>
#include <functional>
#include <random>
std::string create_uuid()
{
std::stringstream stream;
auto random_seed = std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937 seed_engine(random_seed);
std::uniform_int_distribution<std::size_t> random_gen ;
std::size_t value = random_gen(seed_engine);
stream << std::hex << value;
return stream.str();
}
利用当前时钟,产生随机数,产生uuid