Project

General

Profile

Actions

Task #5340

closed

Avoid repeatedly initializing new random generators every time random number is generated

Added by Alexander Lane 10 days ago. Updated 9 days ago.

Status:
Closed
Priority:
Normal
Category:
Unit Tests
Target version:
-
Start date:
12/12/2024
Due date:
% Done:

0%

Estimated time:

Description

During the refactoring in b8bd5ee965, NFD moved from trying to retrieve a globally shared std::mt19937 object to calling ndn::random::getRandomNumberEngine() instead. This currently yields a new thread local instance of a std::mt19937/RandomNumberEngine object every time it's called. While this is not obviously a functional issue, as we currently generate a new seed sequence every time which should yield a new random number, it is both seemingly inefficient and also makes it more difficult to introduce a seeded RNG for unit testing or trying to otherwise ensure repeatable behavior. It would be sensible to refactor sections of code which rely on this to either use a consistent RandomNumberEngine object local to their instance or to return to maintaining a single common RNG globally.

Actions

Also available in: Atom PDF