From b6e7ed20ceeef606d2412f5e3f69d3224011d69f Mon Sep 17 00:00:00 2001 From: Philipp Moritz Date: Tue, 22 Oct 2019 17:52:12 -0700 Subject: [PATCH] Fix random numbers on linux wheel build (#5975) --- BUILD.bazel | 2 +- src/ray/util/sample.h | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 8867ff384..58760d239 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -595,7 +595,7 @@ cc_library( deps = [ ":sha256", "@com_github_google_glog//:glog", - "@com_google_absl//absl/random", + "@com_google_absl//absl/time", "@plasma//:plasma_client", ], ) diff --git a/src/ray/util/sample.h b/src/ray/util/sample.h index 40c1bc0bf..df36e1588 100644 --- a/src/ray/util/sample.h +++ b/src/ray/util/sample.h @@ -1,8 +1,9 @@ #ifndef RAY_UTIL_SAMPLE_H #define RAY_UTIL_SAMPLE_H -#include "absl/random/random.h" -#include "absl/random/uniform_int_distribution.h" +#include + +#include "absl/time/clock.h" // Randomly samples num_elements from the elements between first and last using reservoir // sampling. @@ -10,17 +11,17 @@ template ::val void random_sample(Iterator begin, Iterator end, size_t num_elements, std::vector *out) { out->resize(0); - absl::BitGen gen; if (num_elements == 0) { return; } + std::default_random_engine gen(absl::GetCurrentTimeNanos()); size_t current_index = 0; for (auto it = begin; it != end; it++) { if (current_index < num_elements) { out->push_back(*it); } else { - size_t random_index = absl::uniform_int_distribution(0, current_index)(gen); + size_t random_index = std::uniform_int_distribution(0, current_index)(gen); if (random_index < num_elements) { out->at(random_index) = *it; }