Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/numeric/random/seed seq"

From cppreference.com
< cpp‎ | numeric‎ | random
m (Text replace - "{{tdcl" to "{{dcl")
m (Text replace - "/sidebar" to "/navbar")
Line 1: Line 1:
 
{{cpp/title|seed_seq}}
 
{{cpp/title|seed_seq}}
{{cpp/numeric/random/uniform_real_distribution/sidebar}}
+
{{cpp/numeric/random/uniform_real_distribution/navbar}}
 
{{ddcl | header=random | notes={{mark since c++11}} | 1=
 
{{ddcl | header=random | notes={{mark since c++11}} | 1=
 
class seed_seq;
 
class seed_seq;

Revision as of 13:56, 15 June 2012

 
 
 
 
 
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 Template:concept.

Member types

Member type Definition
result_type uint_least32_t

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)

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:

3890079369
567513683
1868094942
738085780
2849436979
1267185068
3817490445
2911200628
2374022914
1233116465