疑似乱数生成器 xoroshiro128++
lib/random/xoroshiro128.hpp
インクルード
#include "random/xoroshiro128.hpp"
クラス
| 名前 | 説明 |
|---|---|
Xoroshiro128 |
疑似乱数生成器 xoroshiro128++ |
依存するヘッダ(2)
-
疑似乱数生成器の共通部分(CRTP)
lib/internal/internal_random.hpp -
疑似乱数生成器 SplitMix64
lib/random/split_mix64.hpp
このヘッダを使うライブラリ(5)
-
要素の挿入・削除が可能な動的ウェーブレット行列
lib/data_structure/dynamic_wavelet_matrix.hpp -
動的完備辞書
lib/internal/dynamic_bit_vector.hpp -
素因数分解
lib/number_theory/factorize.hpp -
素数列挙・判定
lib/number_theory/prime_number.hpp -
Zobrist ハッシュ
lib/random/zobrist_hash.hpp
検証プログラム(12)
-
test/aoj/challenge/0009.test.cpp
test/aoj/challenge/0009.test.cpp -
test/aoj/challenge/1276.test.cpp
test/aoj/challenge/1276.test.cpp -
test/aoj/course/ALDS1_1_C.test.cpp
test/aoj/course/ALDS1_1_C.test.cpp -
test/aoj/ntl/prime_factorize.test.cpp
test/aoj/ntl/prime_factorize.test.cpp -
test/yosupo/convolution/gcd_convolution.test.cpp
test/yosupo/convolution/gcd_convolution.test.cpp -
test/yosupo/convolution/lcm_convolution.test.cpp
test/yosupo/convolution/lcm_convolution.test.cpp -
test/yosupo/data_structure/point_set_range_frequency.test.cpp
test/yosupo/data_structure/point_set_range_frequency.test.cpp -
test/yosupo/number_theory/factorize.test.cpp
test/yosupo/number_theory/factorize.test.cpp -
test/yosupo/number_theory/primitive_root.test.cpp
test/yosupo/number_theory/primitive_root.test.cpp -
test/yosupo/tree/rooted_tree_isomorphism_classification.test.cpp
test/yosupo/tree/rooted_tree_isomorphism_classification.test.cpp -
test/yukicoder/0843.test.cpp
test/yukicoder/0843.test.cpp -
test/yukicoder/1611.test.cpp
test/yukicoder/1611.test.cpp
実装
#pragma once
#include <array>
#include <bit>
#include <cstdint>
#include "internal/internal_random.hpp"
#include "random/split_mix64.hpp"
/// @brief 疑似乱数生成器 xoroshiro128++
/// @complexity すべての操作が $O(1)$
struct Xoroshiro128 : internal::RandomEngineBase<Xoroshiro128, std::array<std::uint64_t, 2>, std::uint64_t> {
/// @brief 既定seedで構築する
/// @complexity $O(1)$
constexpr Xoroshiro128() noexcept : RandomEngineBase(SplitMix64{}.generate_seed_sequence<2>()) {}
/// @brief 指定seedで構築する
/// @complexity $O(1)$
constexpr Xoroshiro128(std::uint64_t seed) noexcept
: RandomEngineBase(SplitMix64{seed}.generate_seed_sequence<2>()) {}
/// @brief 次の64bit乱数を返す
/// @complexity $O(1)$
constexpr result_type operator()() noexcept {
const std::uint64_t s0 = state[0];
std::uint64_t s1 = state[1];
const std::uint64_t result = std::rotl(s0 + s1, 17) + s0;
s1 ^= s0;
state[0] = std::rotl(s0, 49) ^ s1 ^ (s1 << 21), state[1] = std::rotl(s1, 28);
return result;
}
};