mirror of
https://github.com/wassname/ray.git
synced 2026-07-25 13:30:52 +08:00
Fix random numbers on linux wheel build (#5975)
This commit is contained in:
+1
-1
@@ -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",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -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 <random>
|
||||
|
||||
#include "absl/time/clock.h"
|
||||
|
||||
// Randomly samples num_elements from the elements between first and last using reservoir
|
||||
// sampling.
|
||||
@@ -10,17 +11,17 @@ template <class Iterator, class T = typename std::iterator_traits<Iterator>::val
|
||||
void random_sample(Iterator begin, Iterator end, size_t num_elements,
|
||||
std::vector<T> *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<size_t>(0, current_index)(gen);
|
||||
size_t random_index = std::uniform_int_distribution<size_t>(0, current_index)(gen);
|
||||
if (random_index < num_elements) {
|
||||
out->at(random_index) = *it;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user