Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions cpp/src/plasma/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#include "plasma/common.h"

#include <limits>
#include <mutex>
#include <random>

#include "plasma/plasma_generated.h"
Expand All @@ -28,9 +30,15 @@ using arrow::Status;
UniqueID UniqueID::from_random() {
UniqueID id;
uint8_t* data = id.mutable_data();
std::random_device engine;
// NOTE(pcm): The right way to do this is to have one std::mt19937 per
// thread (using the thread_local keyword), but that's not supported on
// older versions of macOS (see https://stackoverflow.com/a/29929949)
static std::mutex mutex;
std::lock_guard<std::mutex> lock(mutex);
static std::mt19937 generator;
std::uniform_int_distribution<uint32_t> dist(0, std::numeric_limits<uint8_t>::max());
for (int i = 0; i < kUniqueIDSize; i++) {
data[i] = static_cast<uint8_t>(engine());
data[i] = static_cast<uint8_t>(dist(generator));
}
return id;
}
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/plasma/test/client_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class TestPlasmaStore : public ::testing::Test {
// TODO(pcm): At the moment, stdout of the test gets mixed up with
// stdout of the object store. Consider changing that.
void SetUp() {
std::mt19937 rng;
rng.seed(std::random_device()());
uint64_t seed = std::chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(static_cast<uint32_t>(seed));
std::string store_index = std::to_string(rng());
store_socket_name_ = "/tmp/store" + store_index;

Expand Down