std::indepe..._bits_engine(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸŽ€ 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 ✨

  1. Default constructor. The underlying engine gets default-constructed too. no thoughts, head empty, still random 🫢
  2. Constructs the underlying engine with s.
  3. Constructs the underlying engine with the seed sequence seq. big caveat incoming β€” this constructor only participates in overload resolution if Sseq qualifies as a SeedSequence. In particular, it does not participate in overload resolution if Sseq is implicitly convertible to result_type. ngl that's the kind of rule that'll get you if you're not paying attention 😭
  4. Constructs the underlying engine with a copy of e. copy slay πŸ’…
  5. Move-constructs the underlying engine with e. afterwards e holds 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 with
  • seq β€” seed sequence to construct the underlying engine with
  • e β€” 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