Random number engines shall not be default-initialized
Random number engines shall not be default-initialized.
Pseudorandom number generators depend on an initial seed value to generate a sequence of random numbers. Default initialization of random number engines is done by using a default seed, which is a constant value. If you call a random number generator that has default initialization multiple times, you get the same sequence every time. To generate nonrepeating random number sequences, use unique, nondefault seed values each time that you initialize a random number generator.
This rule prevents the generation of deterministic sequences in production code where randomness is required. An exception to this rule is allowed when a deterministic sequence is required for consistent testing purposes.
The checker reports violations on the lines in which:
A C++ standard random number generator is default-initialized.
The seeding function of a random number generator is called by using an implicit
call to default arguments or an explicit default_seed
argument..
Note
The checker does not report random number engine initializations that have constant input arguments.
If you expect a rule violation but do not see it, refer to the documentation for Polyspace® Bug Finder™ or Polyspace Bug Finder Server™.
| Group: Algorithms library |
| Category: Required, Automated |