-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
-
Service Arch
-
Fully Compatible
-
ALL
-
Service Arch 2022-12-26, Service Arch 2023-01-09
-
135
The C rand() function should never be used in server code.
It's a very weak random generator.
It's not guaranteed to be reentrant.
It's hard to control (and easy to forget to control) the seed https://jira.mongodb.org/browse/SERVER-72366
All callers should be changed to use PseudoRandom or equivalent mongo/platform/random.h facilities.
mongo/platform/random.h should provide a way to get a parameter-controlled and injectable seed. Perhaps from a keyed registry of them? For testability, components should be able to use their injectable random seed in peace without worrying about other unrelated components messing up the sequence by adding requests for random numbers from the same source (BF-27216). A global singleton pseudorandom generator should therefore not be created.
There is some server code that uses rand() today, incorrectly.
These should be upgraded to PseudoRandom at least.
- is duplicated by
-
SERVER-72374 Replace `std::rand` usages in query analyzer code path
- Closed
- is related to
-
SERVER-72366 Pass random seed to `srand` for unit tests
- Closed
-
SERVER-46514 Normalize host selection for mirrored reads sampling
- Closed