Namespaces
Variants
Views
Actions

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

From cppreference.com
< cpp‎ | numeric‎ | random
m (Text replace - "{{tdcl list begin" to "{{dcl list begin")
(Wording update.)
 
(16 intermediate revisions by 9 users not shown)
Line 1: Line 1:
 
{{cpp/title|seed_seq}}
 
{{cpp/title|seed_seq}}
{{cpp/numeric/random/uniform_real_distribution/sidebar}}
+
{{cpp/numeric/random/seed_seq/navbar}}
{{ddcl | header=random | notes={{mark since c++11}} | 1=
+
{{ddcl|header=random|since=c++11|
 
class seed_seq;
 
class seed_seq;
 
}}
 
}}
  
{{tt|std::seed_seq}} consumes a sequence of integer-valued data and produces a requested number of unsigned integer values {{tt|i}}, {{math|0 ≤ i < 2{{su|p=32}}}}, based on the consumed data. The produced values are distributed over the entire 32-bit range even if the consumed values are close.
+
{{tt|std::seed_seq}} consumes a sequence of integer-valued data and produces a requested number of 32-bit unsigned integer values, 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.
 
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.
  
{{tt|std::seed_seq}} meets the requirements of {{concept|SeedSequence}}.
+
{{ttt|std::seed_seq}} meets the requirements of {{named req|SeedSequence}}.
  
===Member types===
+
===Nested types===
{{dcl list begin}}
+
{{dsc begin}}
{{tdcl list hitem | Member type | Definition}}
+
{{dsc hitem|Type|Definition}}
{{tdcl list item | {{tt|result_type}} | {{c|uint_least32_t}}}}
+
{{dsc|{{tt|result_type}}|{{lc|std::uint_least32_t}}}}
{{tdcl list end}}
+
{{dsc end}}
 +
 
 +
===Data members===
 +
{{dsc begin}}
 +
{{dsc hitem|Member|Description}}
 +
{{dsc expos mem obj|spec={{c/core|std::vector<result_type>}}|v|id=v|the underlying seed sequence}}
 +
{{dsc end}}
  
 
===Member functions===
 
===Member functions===
{{dcl list begin}}
+
{{dsc begin}}
{{dcl list mem ctor | cpp/numeric/random/seed_seq/seed_seq | constructs and seeds the std::seed_seq object}}
+
{{dsc mem ctor|cpp/numeric/random/seed_seq/seed_seq|constructs and seeds the {{tt|std::seed_seq}} object}}
{{dcl list mem fun | nolink=true | operator{{=}} | not copy-assignable | notes={{mark|deleted}}}}
+
{{dsc mem fun|nolink=true|operator{{=}}|notes={{cmark|deleted}}|{{tt|std::seed_seq}} is not assignable}}
{{dcl list mem fun | cpp/numeric/random/seed_seq/generate | calculates the bias-eliminated, evenly distributed 32-bit values}}
+
{{dsc mem fun|cpp/numeric/random/seed_seq/generate|calculates the bias-eliminated, evenly distributed 32-bit values}}
{{dcl list mem fun | cpp/numeric/random/seed_seq/size | obtains the number of 32-bit values stored in std::seed_seq }}
+
{{dsc mem fun|cpp/numeric/random/seed_seq/size|obtains the number of stored 32-bit values}}
{{dcl list mem fun | cpp/numeric/random/seed_seq/param | obtains the 32-bit values stored in std::seed_seq}}
+
{{dsc mem fun|cpp/numeric/random/seed_seq/param|copies all stored 32-bit values}}
{{dcl list end}}
+
{{dsc end}}
  
 
===Example===
 
===Example===
 
 
{{example
 
{{example
|
+
|code=
| code=
+
#include <cstdint>
#include <random>
+
 
#include <iostream>
 
#include <iostream>
 +
#include <random>
 +
 
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';
 
}
 
}
| output=
+
|p=true
3890079369
+
|output=
567513683
+
4204997637
1868094942
+
4246533866
738085780
+
1856049002
2849436979
+
1129615051
1267185068
+
690460811
3817490445
+
1075771511
2911200628
+
46783058
2374022914
+
3904109078
1233116465
+
1534123438
 +
1495905678
 
}}
 
}}
 +
 +
{{langlinks|de|es|fr|it|ja|pt|ru|zh}}

Latest revision as of 23:36, 22 October 2024

 
 
 
 
 
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 32-bit unsigned integer values, 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.

Contents

[edit] Nested types

Type Definition
result_type std::uint_least32_t

[edit] Data members

Member Description
std::vector<result_type> v the underlying seed sequence
(exposition-only member object*)

[edit] Member functions

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

[edit] Example

#include <cstdint>
#include <iostream>
#include <random>
 
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