diff --git a/cpp/src/plasma/common.cc b/cpp/src/plasma/common.cc index 2de06d5f8cf..be3fc74b062 100644 --- a/cpp/src/plasma/common.cc +++ b/cpp/src/plasma/common.cc @@ -17,6 +17,8 @@ #include "plasma/common.h" +#include +#include #include #include "plasma/plasma_generated.h" @@ -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 lock(mutex); + static std::mt19937 generator; + std::uniform_int_distribution dist(0, std::numeric_limits::max()); for (int i = 0; i < kUniqueIDSize; i++) { - data[i] = static_cast(engine()); + data[i] = static_cast(dist(generator)); } return id; } diff --git a/cpp/src/plasma/test/client_tests.cc b/cpp/src/plasma/test/client_tests.cc index b80862d95b4..23d2c2b1a53 100644 --- a/cpp/src/plasma/test/client_tests.cc +++ b/cpp/src/plasma/test/client_tests.cc @@ -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(seed)); std::string store_index = std::to_string(rng()); store_socket_name_ = "/tmp/store" + store_index;