﻿# V2636\. MISRA\. The functions with the 'rand' and 'srand' name of <stdlib\.h\> should not be used\.

This diagnostic rule is based on the [MISRA](https://www.misra.org.uk/) \(Motor Industry Software Reliability Association\) software development guidelines\.

This diagnostic rule is relevant only for C\.

The `rand` and `srand` functions from the `<stdlib.h>` header file, as well as macros with these names, should not be used\.

The [`srand`](https://en.cppreference.com/w/cpp/numeric/random/srand) and [`rand`](https://en.cppreference.com/w/cpp/numeric/random/rand) functions are used to work with a pseudorandom number generator\. The first function initializes it with a seed value, while the second generates a pseudorandom number\.

However, this functionality has a serious drawback: it does not guarantee the quality of the pseudorandom number sequence\. So, this functionality from the `<stdlib.h>` header file is not recommended for serious tasks that involve pseudorandom numbers\.

The code example where the analyzer issues the warning:

```cpp
int foo()
{
  srand(time(NULL));
  int random_variable = rand();
}
```

The analyzer will also issue warnings for using macros with these names:

```cpp
#define srand printf("msg%i\n", x);
void PositiveTestMacro()
{
  int x =42;
  srand(x);
}
```