Seed Sequence¶
The goal of seed_seq
is to generate reasonable seed data based on multiple entropy arguments or multiple fixed seeds. It is an alternative implementation of M. E. O'Neill's seed_seq
Alternative. Take a look at her website to find out how it is working. seed_seq
is a k-to-1 mapping and has good avalanche properties. In general, it provides much better behavior than std::seed_seq
. We recommend to use seed_seq
when possible.
Scalar¶
namespace pxart {
template <typename T, size_t N>
struct seed_seq;
using seed_seq_4x32 = seed_seq<uint32_t, 4>;
using seed_seq_8x32 = seed_seq<uint32_t, 8>;
using seed_seq_4x64 = seed_seq<uint64_t, 4>;
}
Include Scheme¶
#include <pxart/seed_seq.hpp>
Member Types and Type Variables¶
using uint_type = T;
using result_type = uint_type;
static constexpr size_t state_size = N;
Member Functions¶
Construction¶
constexpr seed_seq() noexcept;
pxart::seed_seq
. Calls other constructor with std::initializer_list
and argument {1, 2, 3, 4}
. template <typename U>
seed_seq(std::initializer_list<U> init) noexcept;
template <typename InputIt>
seed_seq(InputIt begin, InputIt end) noexcept;
Generation¶
constexpr result_type operator()() noexcept;
Example¶
#include <iomanip>
#include <iostream>
//
#include <pxart/mt19937.hpp>
#include <pxart/seed_seq.hpp>
using namespace std;
int main() {
// Construct PRNG by seeding it with seed_seq_8x32 which itself uses four
// fixed seed values.
pxart::seed_seq_8x32 seeder{1, 2, 3, 4};
pxart::mt19937 rng{seeder};
// Return some pseudorandom numbers.
for (int i = 0; i < 10; ++i) cout << setw(15) << rng() << '\n';
}
Last update: January 18, 2021