std::linear...ntial_engine(3)

๐Ÿ“ฆ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

๐ŸŒธ std::linear...ntial_engine(3) ๐ŸŒธ

okay bestie, this is the manual page for std::linear...ntial_engine(3) from the C++ Standard Libary โ€” and yes, thatโ€™s literally how the header spells it, no cap ๐Ÿ’€. Weโ€™re folding the manual name in right here so you know what universe weโ€™re in: C++ Standard Library constructor territory, and itโ€™s giving very specific seed energy โœจ.


๐ŸŽ€ NAME ๐ŸŽ€

  • std::linear_congruential_engine::linear_congruential_engine โ€” aka std::linear_congruential_engine::linear_congruential_engine. The NAME section really said โ€œsay it twice, itโ€™s iconicโ€ ๐Ÿ’….

โœจ Synopsis โœจ

Hereโ€™s the synopsis exactly as the page lays it out, annotations and all โ€” do not come for me about the formatting, Iโ€™m just the messenger ๐Ÿซถ:

linear_congruential_engine() :                                    (1)
(since C++11)
linear_congruential_engine(default_seed) {}
explicit linear_congruential_engine( result_type value );         (2)
(since C++11)
template< class SeedSeq >                                         (3)
(since C++11)
explicit linear_congruential_engine( SeedSeq& seq );
linear_congruential_engine( const linear_congruential_engine&
(since C++11)
other );                                                          (4)
(implicitly
                                                                        declared)

So whatโ€™s the vibe? It constructs the pseudo-random number engine. Thatโ€™s the whole main-character job ๐Ÿ’ซ.

  1. The default constructor. Thatโ€™s it. Thatโ€™s the tweet โœจ.
  2. Constructs the engine with a seed value value. The engineโ€™s initial state is determined like this:
    • If c % m == 0 and value % m == 0 are both true, the state is 1.
    • Otherwise, the state is value % m.
  3. Constructs the engine with a seed sequence seq. Given std::size_t(std::log2(m) / 32) + 1 as k, the engineโ€™s initial state is determined like this:
    1. Creates an invented array object a of length k + 3.
    2. Calls seq.generate(a + 0, a + k + 3).
    3. Let S be ((\sum^{k-1}_{j=0} a_{j+3} \cdot 2^{32j}) \mod m) โ€” and the page also shows the rendered form (โˆ‘k-1 j=0 a j+3ยท232j ) mod m.
    4. If both c % m == 0 and S == 0 are true, sets the engineโ€™s state to 1. Otherwise, sets the engineโ€™s state to S.

This overload participates in overload resolution only if SeedSeq meets the requirements of SeedSequence ๐Ÿ‘‘.

  1. The copy constructor. Upon construction, *this == other is true. Copy constructor ate, no crumbs ๐Ÿ’….

๐ŸŒˆ Parameters ๐ŸŒˆ

  • value โ€” seed value to use in the initialization of the internal state.
  • seq โ€” seed sequence to use in the initialization of the internal state.

๐Ÿฆ‹ Complexity ๐Ÿฆ‹

1, 2) Constant.

  1. Same as the complexity of the seq.generate call.
  2. Constant.

๐Ÿฉน Defect reports ๐Ÿฉน

The following behavior-changing defect reports were applied retroactively to previously published C++ standards โ€” yes, they went back and edited the lore ๐Ÿ˜ญ:

  • DR: P0935R0
  • Applied to: C++11
  • Behavior as published: the default constructor was explicit
  • Correct behavior: made implicit

๐Ÿ”ฅ See also ๐Ÿ”ฅ

  • seed โ€” sets the current state of the engine (C++11) (public member function).

source/version: cppreference.com ยท date: 2024.06.10 ยท page stamp: std::linear...ntial_engine(3) โ€” bye bestie, go seed something iconic ๐Ÿ’–โœจ๐ŸŽ€

๐Ÿ“ฆ where this page comes from