Qt-Autosar-A26.5.2¶
Random number engines shall not be default-initialized
Required inputs: IR
Bad code (default-constructed random engine):
std::mt19937 engine; // ERROR: default seed, predictable sequence int value = engine(); // Poor quality random numbers
Good code (seeded random engine):
std::random_device rd; std::array<int, std::mt19937::state_size> seed_data; std::generate_n(seed_data.data(), seed_data.size(), std::ref(rd)); std::seed_seq seq(std::begin(seed_data), std::end(seed_data)); std::mt19937 engine(seq); // OK: properly seeded with random device int value = engine(); // Good quality random numbers
Good code (using std::seed_seq):
std::seed_seq seed{1, 2, 3, 4, 5};
std::mt19937 engine(seed); // OK: explicit seed sequence
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
forbidden_default_constructor_call |
Call to forbidden default constructor. |
None |
False |
Options¶
This rule shares the following common options: exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
blacklist¶
blacklist
Set of forbidden class names where calling the default constructor is forbidden.Type: set[bauhaus.analysis.config.QualifiedName]
Default:
{'std::default_random_engine', 'std::knuth_b', 'std::linear_congruential_engine', 'std::mersenne_twister_engine', 'std::minstd_rand0', 'std::mt19937', 'std::mt19937_64', 'std::ranlux24', 'std::ranlux24_baset', 'std::ranlux48', 'std::ranlux48_base', 'std::subtract_with_carry_engine'}