std::seed_seq

From cppreference.com
 
 
 
Pseudo-random number generation
Engines and engine adaptors
linear_congruential_engine (C++11)
mersenne_twister_engine (C++11)
subtract_with_carry_engine (C++11)
discard_block_engine (C++11)
independent_bits_engine (C++11)
shuffle_order_engine (C++11)
Generators
random_device (C++11)
Distributions
Uniform distributions
uniform_int_distribution (C++11)
uniform_real_distribution (C++11)
generate_canonical (C++11)
Bernoulli distributions
bernoulli_distribution (C++11)
binomial_distribution (C++11)
negative_binomial_distribution (C++11)
geometric_distribution (C++11)
Poisson distributions
poisson_distribution (C++11)
exponential_distribution (C++11)
gamma_distribution (C++11)
weibull_distribution (C++11)
extreme_value_distribution (C++11)
Normal distributions
normal_distribution (C++11)
lognormal_distribution (C++11)
chi_squared_distribution (C++11)
cauchy_distribution (C++11)
fisher_f_distribution (C++11)
student_t_distribution (C++11)
Sampling distributions
discrete_distribution (C++11)
piecewise_constant_distribution (C++11)
piecewise_linear_distribution (C++11)
Seed Sequences
seed_seq (C++11)
C library
rand
srand
RAND_MAX
 
 
Defined in header <random>
class seed_seq;
(since C++11)

std::seed_seq consumes a sequence of integer-valued data and produces a requested number of unsigned integer values i, 0 ≤ i < 232
, based on the consumed data. The produced values are distributed over the entire 32-bit range even if the consumed values are close.

It provides a way to seed a large number of random number engines or to seed a generator that requires a lot of entropy, given a small seed or a poorly distributed initial seed sequence.

std::seed_seq meets the requirements of SeedSequence.

[edit] Member types

Member type Definition
result_type std::uint_least32_t

[edit] Member functions

constructs and seeds the std::seed_seq object
(public member function)
operator=
(deleted)
not copy-assignable
(public member function)
calculates the bias-eliminated, evenly distributed 32-bit values
(public member function)
obtains the number of 32-bit values stored in std::seed_seq
(public member function)
obtains the 32-bit values stored in std::seed_seq
(public member function)

[edit] Example

#include <random>
#include <iostream>
 
int main()
{
    std::seed_seq seq({1,2,3,4,5});
    std::vector<std::uint32_t> seeds(10);
    seq.generate(seeds.begin(), seeds.end());
    for(std::uint32_t n : seeds)
        std::cout << n << '\n';
}

Output:

4204997637
4246533866
1856049002
1129615051
690460811
1075771511
46783058
3904109078
1534123438
1495905678