Boost C++ 库

……是世界上备受推崇且设计精湛的 C++ 库项目之一。 Herb SutterAndrei Alexandrescu, C++ Coding Standards

Class splitmix64 - Boost C++ 函数库
PrevUpHomeNext

Class splitmix64

boost::random::splitmix64

提要

// In header: <boost/random/splitmix64.hpp>


class splitmix64 {
public:
  // types
  typedef std::uint64_t result_type;
  typedef std::uint64_t seed_type;  

  // private member functions
  std::uint64_t concatenate(std::uint32_t, std::uint32_t) noexcept;

  // public member functions
  void seed(result_type = 0) noexcept;
  template<typename Sseq, 
           typename std::enable_if<!std::is_convertible< Sseq, std::uint64_t >::value, bool >::type = true> 
    void seed(Sseq &);
  template<typename Sseq, 
           typename std::enable_if<!std::is_convertible< Sseq, splitmix64 >::value, bool >::type = true> 
    explicit splitmix64(Sseq &);
  template<typename T, 
           typename std::enable_if< std::is_convertible< T, std::uint64_t >::value, bool >::type = true> 
    void seed(T = 0) noexcept;
  explicit splitmix64(std::uint64_t = 0) noexcept;
  splitmix64(const splitmix64 &) = default;
  splitmix64 & operator=(const splitmix64 &) = default;
  result_type next() noexcept;
  result_type operator()() noexcept;
  void discard(std::uint64_t) noexcept;
  template<typename FIter> void generate(FIter, FIter) noexcept;

  // friend functions
  bool operator==(const splitmix64 &, const splitmix64 &) noexcept;
  bool operator!=(const splitmix64 &, const splitmix64 &) noexcept;
  template<typename CharT, typename Traits> 
    std::basic_ostream< CharT, Traits > & 
    operator<<(std::basic_ostream< CharT, Traits > &, const splitmix64 &);
  template<typename CharT, typename Traits> 
    std::basic_istream< CharT, Traits > & 
    operator>>(std::basic_istream< CharT, Traits > &, splitmix64 &);

  // public static functions
  static constexpr max() noexcept;
  static constexpr min() noexcept;

  // public data members
  static bool has_fixed_range;
};

描述

这是 Java 8 的 SplittableRandom 生成器的固定增量版本。参见 http://dx.doi.org/10.1145/2714064.2660195http://docs.oracle.com/javase/8/docs/api/java/util/SplittableRandom.html。它是一个非常快速的生成器,通过了 BigCrush 测试,如果您出于某种原因绝对需要 64 位状态,那么它很有用;否则,我们建议使用 xoroshiro128+(用于中等并行计算)或 xorshift1024*(用于大规模并行计算)生成器。

splitmix64 私有成员函数

  1. std::uint64_t concatenate(std::uint32_t word1, std::uint32_t word2) noexcept;

splitmix64 公有成员函数

  1. void seed(result_type value = 0) noexcept;

    使用默认种子初始化生成器。

  2. template<typename Sseq, 
             typename std::enable_if<!std::is_convertible< Sseq, std::uint64_t >::value, bool >::type = true> 
      void seed(Sseq & seq);

    使用 seq.generate() 生成的 32 位值来播种生成器。

  3. template<typename Sseq, 
             typename std::enable_if<!std::is_convertible< Sseq, splitmix64 >::value, bool >::type = true> 
      explicit splitmix64(Sseq & seq);

    使用 seq.generate() 生成的 64 位值来播种生成器。

  4. template<typename T, 
             typename std::enable_if< std::is_convertible< T, std::uint64_t >::value, bool >::type = true> 
      void seed(T value = 0) noexcept;

    使用用户提供的种子来播种生成器。

  5. explicit splitmix64(std::uint64_t state = 0) noexcept;

    使用用户提供的种子来播种生成器。

  6. splitmix64(const splitmix64 & other) = default;
  7. splitmix64 & operator=(const splitmix64 & other) = default;
  8. result_type next() noexcept;

    返回生成器的下一个值。

  9. result_type operator()() noexcept;

    返回生成器的下一个值。

  10. void discard(std::uint64_t z) noexcept;

    将生成器的状态向前推进 z

  11. template<typename FIter> void generate(FIter first, FIter last) noexcept;

    用随机值填充一个范围

splitmix64 友元函数

  1. bool operator==(const splitmix64 & lhs, const splitmix64 & rhs) noexcept;

    如果两个生成器将产生相同的数值序列,则返回 true。

  2. bool operator!=(const splitmix64 & lhs, const splitmix64 & rhs) noexcept;

    如果两个生成器将产生不同的数值序列,则返回 true。

  3. template<typename CharT, typename Traits> 
      std::basic_ostream< CharT, Traits > & 
      operator<<(std::basic_ostream< CharT, Traits > & ost, const splitmix64 & e);

    splitmix64 写入 std::ostream

  4. template<typename CharT, typename Traits> 
      std::basic_istream< CharT, Traits > & 
      operator>>(std::basic_istream< CharT, Traits > & ist, splitmix64 & e);

    std::istream 读取 splitmix64

splitmix64 公有静态函数

  1. static constexpr max() noexcept;

    返回 splitmix64 可以产生的最大值。

  2. static constexpr min() noexcept;

    返回 splitmix64 可以产生的最小值。


PrevUpHomeNext