MISRA C:2012 Rule 21.24
Description
Rule Definition
The random number generator functions of <stdlib.h>
shall not be used.
This rule comes from MISRA C™: 2012 Amendment 3.
Rationale
The numbers generated by rand()
are pseudorandom and depend on a
seed set by srand()
. Because of this, the numbers generated by
rand()
can be predicted and are cryptographically weak. Using
srand()
by itself is superfluous as the code sets a seed value for
random number generation but does not use it.
Polyspace Implementation
Polyspace® reports a violation of this rule whenever the code contains
rand()
or srand()
.
Troubleshooting
If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group:Standard Libraries |
Category: Required |
AGC Category: Required |
Version History
Introduced in R2024a