std::mersen...ngine::seed(3)

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

🌟 std::mersenne_twister_engine::seed(3) β€” bestie's guide to seeding 🌟

okay so bestie, you wanna seed your random-number engine? this is THE function. it's giving main character energy for your PRNG. no cap, it's literally called seed. let's get into it. πŸ’…


✨ Synopsis ✨

void seed( result_type value = default_seed ); (1) (since C++11)
template< class SeedSeq >                      (2) (since C++11)
void seed( SeedSeq& seq );

so there are two flavors, bestie. one takes a result_type value (defaults to default_seed), and the other takes a SeedSeq&. both are since C++11, so we're living in the future. πŸš€

  1. right after you set the state, this thing is equal to std::mersenne_twister_engine(value) β€” like, literally identical. slay.
  2. same deal with seq: it matches std::mersenne_twister_engine(seq). periodt.

πŸ’– Parameters πŸ’–

  • value β€” the seed value you're using to set the state. (like, the vibe you're giving it ✨)
  • seq β€” the seed sequence you're using to set the state. (a whole sequence of vibes πŸŒ€)

😭 Exceptions 😭

throws nothing. literally zero throws. not even a little one. periodt. πŸ’€

πŸŒ€ Complexity πŸŒ€

  1. same as std::mersenne_twister_engine(value).
  2. same as std::mersenne_twister_engine(seq).

so like, however complex that is, this is the same. no extra drama. πŸ’β™€οΈ


🌈 Example 🌈

#include <iostream>
#include <random>

int main()
{
    std::mt19937 gen;

    // Seed the engine with an unsigned int
    gen.seed(1);
    std::cout << "after seed by 1: " << gen() << '\n';

    // Seed the engine with two unsigned ints
    std::seed_seq sseq{1, 2};
    gen.seed(sseq);
    std::cout << "after seed by {1,2}: " << gen() << '\n';
}

and here's what you might see (possible output, bestie):

after seed by 1: 1791095845
after seed by {1,2}: 3127717181

this page is from http://cppreference.com, dated 2024.06.10. stay iconic, bestie. 🫢✨

πŸ“¦ where this page comes from