splitmix64.hpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef BOOST_CORE_DETAIL_SPLITMIX64_HPP_INCLUDED
  2. #define BOOST_CORE_DETAIL_SPLITMIX64_HPP_INCLUDED
  3. // Copyright 2020 Peter Dimov
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // https://www.boost.org/LICENSE_1_0.txt
  6. //
  7. // An implementation of splitmix64 for testing purposes,
  8. // derived from Sebastiano Vigna's public domain implementation
  9. // http://xorshift.di.unimi.it/splitmix64.c
  10. #include <boost/cstdint.hpp>
  11. namespace boost
  12. {
  13. namespace detail
  14. {
  15. class splitmix64
  16. {
  17. private:
  18. boost::uint64_t x_;
  19. public:
  20. splitmix64(): x_( 0 )
  21. {
  22. }
  23. explicit splitmix64( boost::uint64_t seed ): x_( seed )
  24. {
  25. }
  26. boost::uint64_t operator()()
  27. {
  28. x_ += ( boost::uint64_t(0x9e3779b9u) << 32 ) + 0x7f4a7c15u;
  29. boost::uint64_t z = x_;
  30. z ^= z >> 30;
  31. z *= ( boost::uint64_t(0xbf58476du) << 32 ) + 0x1ce4e5b9u;
  32. z ^= z >> 27;
  33. z *= ( boost::uint64_t(0x94d049bbu) << 32 ) + 0x133111ebu;
  34. z ^= z >> 31;
  35. return z;
  36. }
  37. };
  38. } // namespace detail
  39. } // namespace boost
  40. #endif // #ifndef BOOST_CORE_DETAIL_SPLITMIX64_HPP_INCLUDED