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.2660195 和 http://docs.oracle.com/javase/8/docs/api/java/util/SplittableRandom.html。它是一个非常快速的生成器,通过了 BigCrush 测试,如果您出于某种原因绝对需要 64 位状态,那么它很有用;否则,我们建议使用 xoroshiro128+(用于中等并行计算)或 xorshift1024*(用于大规模并行计算)生成器。
splitmix64
公有成员函数void seed(result_type value = 0) noexcept;
使用默认种子初始化生成器。
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 位值来播种生成器。
template<typename Sseq, typename std::enable_if<!std::is_convertible< Sseq, splitmix64 >::value, bool >::type = true> explicit splitmix64(Sseq & seq);
使用 seq.generate()
生成的 64 位值来播种生成器。
template<typename T, typename std::enable_if< std::is_convertible< T, std::uint64_t >::value, bool >::type = true> void seed(T value = 0) noexcept;
使用用户提供的种子来播种生成器。
explicit splitmix64(std::uint64_t state = 0) noexcept;
使用用户提供的种子来播种生成器。
splitmix64(const splitmix64 & other) = default;
splitmix64 & operator=(const splitmix64 & other) = default;
result_type next() noexcept;
返回生成器的下一个值。
result_type operator()() noexcept;
返回生成器的下一个值。
void discard(std::uint64_t z) noexcept;
将生成器的状态向前推进 z
。
template<typename FIter> void generate(FIter first, FIter last) noexcept;
用随机值填充一个范围
splitmix64
友元函数bool operator==(const splitmix64 & lhs, const splitmix64 & rhs) noexcept;
如果两个生成器将产生相同的数值序列,则返回 true。
bool operator!=(const splitmix64 & lhs, const splitmix64 & rhs) noexcept;
如果两个生成器将产生不同的数值序列,则返回 true。
template<typename CharT, typename Traits> std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > & ost, const splitmix64 & e);
将 splitmix64
写入 std::ostream
。
template<typename CharT, typename Traits> std::basic_istream< CharT, Traits > & operator>>(std::basic_istream< CharT, Traits > & ist, splitmix64 & e);
从 std::istream
读取 splitmix64
。
splitmix64
公有静态函数static constexpr max() noexcept;
返回 splitmix64
可以产生的最大值。
static constexpr min() noexcept;
返回 splitmix64
可以产生的最小值。