random_provider.hpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #ifndef BOOST_UUID_DETAIL_RANDOM_PROVIDER_HPP_INCLUDED
  2. #define BOOST_UUID_DETAIL_RANDOM_PROVIDER_HPP_INCLUDED
  3. // Copyright (c) 2017 James E. King III
  4. // Copyright (c) 2024 Peter Dimov
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // https://www.boost.org/LICENSE_1_0.txt
  7. #include <boost/uuid/detail/random_device.hpp>
  8. #include <random>
  9. #include <cstdint>
  10. namespace boost {
  11. namespace uuids {
  12. namespace detail {
  13. class random_provider
  14. {
  15. private:
  16. detail::random_device dev_;
  17. public:
  18. using result_type = std::uint32_t;
  19. random_provider() = default;
  20. // Leverage the provider as a SeedSeq for
  21. // PseudoRandomNumberGeneration seeding.
  22. template<class Iter>
  23. void generate(Iter first, Iter last)
  24. {
  25. std::uniform_int_distribution<std::uint32_t> dist;
  26. for( ; first != last; ++first )
  27. {
  28. *first = dist( dev_ );
  29. }
  30. }
  31. const char * name() const
  32. {
  33. return "std::random_device";
  34. }
  35. };
  36. } // detail
  37. } // uuids
  38. } // boost
  39. #endif // BOOST_UUID_DETAIL_RANDOM_PROVIDER_HPP_INCLUDED