...
The following noncompliant code generates an ID with a numeric part produced by calling the rand()
function. The IDs produced are predictable and have limited randomness. Further, depending on the value of RAND_MAX
, the resulting value has can have modulo bias.
Code Block | ||||
---|---|---|---|---|
| ||||
#include <cstdlib> #include <string> void f() { std::string id("ID"); // Holds the ID, starting with the characters "ID" followed // by a random integer in the range [0-10000]. id += std::to_string(std::rand() % 10000); // ... } |
...