std::indepe..._bits_engine(3)
π NAME π
okay so this page is from the C++ Standard Library manual, std::indepe..._bits_engine(3), and it's all about the constructor of std::independent_bits_engine::independent_bits_engine β yes the name is literally that, it stutters, we love her anyway π
β¨ SYNOPSIS β¨
independent_bits_engine(); (1) (since C++11)
explicit independent_bits_engine( result_type s ); (2) (since C++11)
template< class Sseq > (3) (since C++11)
explicit independent_bits_engine( Sseq& seq );
explicit independent_bits_engine( const Engine& e ); (4) (since C++11)
explicit independent_bits_engine( Engine&& e ); (5) (since C++11)
π DESCRIPTION π
bestie, this is what builds you a brand new pseudo-random engine adaptor. five whole flavours, all of them since C++11, all of them iconic β¨
- Default constructor. The underlying engine gets default-constructed too. no thoughts, head empty, still random π«Ά
- Constructs the underlying engine with
s. - Constructs the underlying engine with the seed sequence
seq. big caveat incoming β this constructor only participates in overload resolution ifSseqqualifies as aSeedSequence. In particular, it does not participate in overload resolution ifSseqis implicitly convertible toresult_type. ngl that's the kind of rule that'll get you if you're not paying attention π - Constructs the underlying engine with a copy of
e. copy slay π - Move-constructs the underlying engine with
e. afterwardseholds an unspecified, but valid, state. so like, she's still alive, she's just not telling you her business π
π¦ PARAMETERS π¦
sβ integer value to construct the underlying engine withseqβ seed sequence to construct the underlying engine witheβ pseudo-random number engine to initialize with
πΈ EXAMPLE πΈ
// Run this code
#include <iostream>
#include <random>
int main()
{
auto print = [](auto rem, auto engine, int count)
{
std::cout << rem << ": ";
for (int i {}; i != count; ++i)
std::cout << static_cast<unsigned>(engine()) << ' ';
std::cout << '\n';
};
std::independent_bits_engine<std::mt19937, /*bits*/ 1, unsigned short>
e1; // default-constructed
print("e1", e1, 8);
std::independent_bits_engine<std::mt19937, /*bits*/ 1, unsigned int>
e2(1); // constructed with 1
print("e2", e2, 8);
std::random_device rd;
std::independent_bits_engine<std::mt19937, /*bits*/ 3, unsigned long>
e3(rd()); // seeded with rd()
print("e3", e3, 8);
std::seed_seq s {3, 1, 4, 1, 5};
std::independent_bits_engine<std::mt19937, /*bits*/ 3, unsigned long long>
e4(s); // seeded with seed-sequence s
print("e4", e4, 8);
}
β POSSIBLE OUTPUT β
e1: 0 0 0 1 0 1 1 1
e2: 1 1 0 0 1 1 1 1
e3: 3 1 5 4 3 2 3 4
e4: 0 2 4 4 4 3 3 6
key word is possible β these are random engines, so don't come for me if your numbers are different, they're supposed to be π₯
that's the whole page babes, no cap. sourced from http://cppreference.com, the 2024.06.10 edition β go forth and seed responsibly π§ββοΈπ
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms