std::mersen...ngine::seed(3)
π 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. π
- right after you set the state, this thing is equal to
std::mersenne_twister_engine(value)β like, literally identical. slay. - same deal with
seq: it matchesstd::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 π
- same as
std::mersenne_twister_engine(value). - 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
- 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