std::bernou...::operator()(3)

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

πŸ’– NAME πŸ’–

okay so bestie, this is the std::bernou...::operator()(3) page, and the manual it lives in is the C++ Standard Libary one (yes, β€œLibary” with one b β€” that’s literally the header, not me typoing, iykyk πŸ’…). The star of the show is std::bernoulli_distribution::operator() β€” the NAME section says it twice, which is giving β€œintroduce yourself twice so they remember you” energy. Periodt.

🌈 Synopsis 🌈

Two overloads, both since C++11, both cute, both doing the random-number thing:

template< class Generator >                                       (1)
(since C++11)
result_type operator()( Generator& g );
template< class Generator >                                       (2)
(since C++11)
result_type operator()( Generator& g, const param_type& params );

They generate random numbers distributed according to the associated probability function. The entropy is acquired by calling g.operator() β€” like, that’s literally where the randomness comes from, no cap. ✨

Version (1) uses the associated parameter set. Version (2) uses params. And important: the associated parameter set is not modified. Leave her alone, she’s not changing. 🫢

πŸŽ€ Parameters πŸŽ€

  • g β€” a uniform random bit generator object 🎲
  • params β€” distribution parameter set to use instead of the associated one

πŸ¦‹ Type requirements πŸ¦‹

  • Generator must meet the requirements of UniformRandomBitGenerator. βœ…

⭐ Return value ⭐

The generated random number. That’s it, that’s the gift. 🎁

πŸ”₯ Complexity πŸ”₯

Amortized constant number of invocations of g.operator(). So, like, on average it’s not doing a whole saga in there. πŸ’€


Source/version and date, per the footer: http://cppreference.com, 2024.06.10, and the page tag is std::bernou...::operator()(3). Cute little sign-off, mwah πŸ’‹πŸ’–

πŸ“¦ where this page comes from