BellUtils.cpp 556 B

12345678910111213141516171819202122232425
  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. }
  17. void bell::freeAndNull(void *&ptr) {
  18. free(ptr);
  19. ptr = nullptr;
  20. }