rand_guid.h 576 B

123456789101112131415161718192021222324252627282930
  1. #pragma once
  2. #include <library/cpp/deprecated/atomic/atomic.h>
  3. #include <util/random/mersenne.h>
  4. #include <type_traits>
  5. namespace NYql {
  6. class TRandGuid {
  7. public:
  8. TRandGuid();
  9. TRandGuid(TRandGuid&&) = default;
  10. TRandGuid& operator=(TRandGuid&&) = default;
  11. void ResetSeed();
  12. TString GenGuid();
  13. ui64 GenNumber();
  14. private:
  15. TMersenne<ui64>& GetRnd() {
  16. return reinterpret_cast<TMersenne<ui64>&>(Rnd_);
  17. }
  18. private:
  19. std::aligned_storage<sizeof(TMersenne<ui64>) ,alignof(TMersenne<ui64>)>::type Rnd_;
  20. static TAtomic Counter;
  21. };
  22. }