8d4b14e001ec026f346c6b4b00509adae7769415
I'd use a different approach to not mix different conditions:
// Filter by network (optional)
if (network != std::nullopt && ai.GetNetClass() != network) continue;
// Filter for quality
if (ai.IsTerrible()) continue;
vAddr.push_back(ai);
Also note that it first filters by network, which I think is slightly better.
I also want to point that IsTerrible default argument is computed in each iteration, I'd suggest:
const int64_t now = GetAdjustedTime();
// gather a list of random nodes, skipping those of low quality
for (unsigned int n = 0; n < vRandom.size(); n++) {
...
if (ai.IsTerrible(now)) continue;