Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:24

0001 //
0002 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // Official repository: https://github.com/boostorg/beast
0008 //
0009 
0010 #ifndef BOOST_BEAST_CORE_DETAIL_PCG_HPP
0011 #define BOOST_BEAST_CORE_DETAIL_PCG_HPP
0012 
0013 #include <boost/core/ignore_unused.hpp>
0014 #include <cstdint>
0015 #include <random>
0016 
0017 namespace boost {
0018 namespace beast {
0019 namespace detail {
0020 
0021 class pcg
0022 {
0023     std::uint64_t state_ = 0;
0024     std::uint64_t increment_;
0025 
0026 public:
0027     using result_type = std::uint32_t;
0028 
0029     // Initialize the generator.
0030     // There are no restrictions on the input values.
0031     pcg(
0032         std::uint64_t seed,
0033         std::uint64_t stream)
0034     {
0035         // increment must be odd
0036         increment_ = 2 * stream + 1;
0037         boost::ignore_unused((*this)());
0038         state_ += seed;
0039         boost::ignore_unused((*this)());
0040     }
0041 
0042     std::uint32_t
0043     operator()()
0044     {
0045         std::uint64_t const p = state_;
0046         state_ = p *
0047             6364136223846793005ULL +
0048             increment_;
0049         std::uint32_t const x =
0050             static_cast<std::uint32_t>(
0051             ((p >> 18) ^ p) >> 27);
0052         std::uint32_t const r = p >> 59;
0053     #ifdef BOOST_MSVC
0054         return _rotr(x, r);
0055     #else
0056         return (x >> r) | (x << ((1 + ~r) & 31));
0057     #endif
0058     }
0059 };
0060 
0061 } // detail
0062 } // beast
0063 } // boost
0064 
0065 #endif