Difference between revisions of "cpp/numeric/random/seed seq"
From cppreference.com
m (~) |
m (fmt) |
||
Line 1: | Line 1: | ||
{{cpp/title|seed_seq}} | {{cpp/title|seed_seq}} | ||
{{cpp/numeric/random/seed_seq/navbar}} | {{cpp/numeric/random/seed_seq/navbar}} | ||
− | {{ddcl | header=random | since=c++11 | | + | {{ddcl|header=random|since=c++11| |
class seed_seq; | class seed_seq; | ||
}} | }} | ||
Line 9: | Line 9: | ||
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. | 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. | ||
− | {{ | + | {{ttt|std::seed_seq}} meets the requirements of {{named req|SeedSequence}}. |
===Member types=== | ===Member types=== | ||
{{dsc begin}} | {{dsc begin}} | ||
− | {{dsc hitem | Member type | Definition}} | + | {{dsc hitem|Member type|Definition}} |
− | {{dsc | {{tt|result_type}}{{mark c++11}} | {{lc|std::uint_least32_t}}}} | + | {{dsc|{{tt|result_type}} {{mark c++11}}|{{lc|std::uint_least32_t}}}} |
{{dsc end}} | {{dsc end}} | ||
===Member functions=== | ===Member functions=== | ||
{{dsc begin}} | {{dsc begin}} | ||
− | {{dsc mem ctor | cpp/numeric/random/seed_seq/seed_seq | notes={{mark c++11}} | constructs and seeds the std::seed_seq object}} | + | {{dsc mem ctor|cpp/numeric/random/seed_seq/seed_seq|notes={{mark c++11}}|constructs and seeds the std::seed_seq object}} |
− | {{dsc mem fun | nolink=true | operator{{=}} | notes={{cmark|deleted}}{{mark c++11}} | {{tt|seed_seq}} is not assignable}} | + | {{dsc mem fun|nolink=true|operator{{=}}|notes={{cmark|deleted}} {{mark c++11}}|{{tt|seed_seq}} is not assignable}} |
− | {{dsc mem fun | cpp/numeric/random/seed_seq/generate | notes={{mark c++11}} | calculates the bias-eliminated, evenly distributed 32-bit values}} | + | {{dsc mem fun|cpp/numeric/random/seed_seq/generate|notes={{mark c++11}}|calculates the bias-eliminated, evenly distributed 32-bit values}} |
− | {{dsc mem fun | cpp/numeric/random/seed_seq/size | notes={{mark c++11}} | obtains the number of 32-bit values stored in std::seed_seq }} | + | {{dsc mem fun|cpp/numeric/random/seed_seq/size|notes={{mark c++11}}|obtains the number of 32-bit values stored in std::seed_seq}} |
− | {{dsc mem fun | cpp/numeric/random/seed_seq/param | notes={{mark c++11}} | obtains the 32-bit values stored in std::seed_seq}} | + | {{dsc mem fun|cpp/numeric/random/seed_seq/param|notes={{mark c++11}}|obtains the 32-bit values stored in std::seed_seq}} |
{{dsc end}} | {{dsc end}} | ||
===Example=== | ===Example=== | ||
{{example | {{example | ||
− | + | |code= | |
− | + | ||
#include <random> | #include <random> | ||
#include <cstdint> | #include <cstdint> | ||
Line 36: | Line 35: | ||
int main() | int main() | ||
{ | { | ||
− | std::seed_seq seq{1,2,3,4,5}; | + | std::seed_seq seq{1, 2, 3, 4, 5}; |
std::vector<std::uint32_t> seeds(10); | std::vector<std::uint32_t> seeds(10); | ||
seq.generate(seeds.begin(), seeds.end()); | seq.generate(seeds.begin(), seeds.end()); | ||
− | for (std::uint32_t n : seeds) | + | for (std::uint32_t n : seeds) |
std::cout << n << '\n'; | std::cout << n << '\n'; | ||
− | |||
} | } | ||
− | + | |p=true | |
+ | |output= | ||
4204997637 | 4204997637 | ||
4246533866 | 4246533866 | ||
Line 53: | Line 52: | ||
3904109078 | 3904109078 | ||
1534123438 | 1534123438 | ||
− | 1495905678 | + | 1495905678 |
}} | }} | ||
{{langlinks|de|es|fr|it|ja|pt|ru|zh}} | {{langlinks|de|es|fr|it|ja|pt|ru|zh}} |
Revision as of 14:58, 8 February 2023
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.
Member types
Member type | Definition |
result_type (C++11)
|
std::uint_least32_t |
Member functions
(C++11) |
constructs and seeds the std::seed_seq object (public member function) |
operator= [deleted] (C++11) |
seed_seq is not assignable (public member function) |
(C++11) |
calculates the bias-eliminated, evenly distributed 32-bit values (public member function) |
(C++11) |
obtains the number of 32-bit values stored in std::seed_seq (public member function) |
(C++11) |
obtains the 32-bit values stored in std::seed_seq (public member function) |
Example
Run this code
#include <random> #include <cstdint> #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'; }
Possible output:
4204997637 4246533866 1856049002 1129615051 690460811 1075771511 46783058 3904109078 1534123438 1495905678