BellUtils.cpp 488 B

1234567891011121314151617181920
  1. #include "BellUtils.h"
  2. std::string bell::generateRandomUUID() {
  3. static std::random_device dev;
  4. static std::mt19937 rng(dev());
  5. std::uniform_int_distribution<int> dist(0, 15);
  6. const char *v = "0123456789abcdef";
  7. const bool dash[] = {0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0};
  8. std::string res;
  9. for (int i = 0; i < 16; i++) {
  10. if (dash[i])
  11. res += "-";
  12. res += v[dist(rng)];
  13. res += v[dist(rng)];
  14. }
  15. return res;
  16. }