Skip to content

Commit

Permalink
update random_device and find
Browse files Browse the repository at this point in the history
  • Loading branch information
Centurybbx committed Nov 8, 2023
1 parent 20d29c4 commit 7aafd54
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#pragma once

#include <cstdlib>
#include <random>
#include <vector>
#include "pstring.h"

Expand Down Expand Up @@ -56,7 +56,11 @@ inline typename HASH::const_iterator FollyRandomHashMember(const HASH& container
}

it = container.cbegin();
size_t randomIdx = random() % container.size();
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dis(0, container.size() - 1);

size_t randomIdx = dis(gen);
while (randomIdx > 0) {
randomIdx--;
++it;
Expand Down
2 changes: 1 addition & 1 deletion src/store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ size_t PStore::BlockedClients::UnblockClient(PClient* client) {
const auto& keys = client->WaitingKeys();

for (const auto& key : keys) {
Clients clients = blockedClients_[key];
Clients clients = blockedClients_.find(key)->second;
assert(!clients.empty());

for (auto it(clients.begin()); it != clients.end(); ++it) {
Expand Down

0 comments on commit 7aafd54

Please sign in to comment.