Revert "Use absl::BitGen to generate Random's seed"
This reverts commit f2556b4ffe51bc25bfa99771801800ddb71aad8e.
Reason for revert: absl::BitGen has issues seeding on Windows10 Chromium render process. https://ci.chromium.org/ui/p/chromium/builders/webrtc.fyi/WebRTC%20Chromium%20FYI%20Win10%20Tester/18543/test-results
Original change's description:
> Use absl::BitGen to generate Random's seed
>
> This adds a default constructor to Random which uses absl::BitGet to
> generate its own seed. This allows us to replace places where the
> current time was used to set a seed.
>
> Bug: webrtc:441137274
> Change-Id: I5afeca99b2fee5e5a2a0b31043ee0c81c00af5cc
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/408005
> Commit-Queue: Evan Shrubsole <eshr@webrtc.org>
> Auto-Submit: Evan Shrubsole <eshr@webrtc.org>
> Reviewed-by: Harald Alvestrand <hta@webrtc.org>
> Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
> Cr-Commit-Position: refs/heads/main@{#45588}
Bug: webrtc:441137274
Change-Id: I7acb39e56cfb119742a2b36f053abd1a43781417
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/408903
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Evan Shrubsole <eshr@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#45619}
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn
index b7ec9d0..4d4014a 100644
--- a/rtc_base/BUILD.gn
+++ b/rtc_base/BUILD.gn
@@ -251,7 +251,6 @@
deps = [
":checks",
":safe_conversions",
- "//third_party/abseil-cpp/absl/random",
]
}
diff --git a/rtc_base/DEPS b/rtc_base/DEPS
index 8ad4997..9e8908c 100644
--- a/rtc_base/DEPS
+++ b/rtc_base/DEPS
@@ -44,7 +44,4 @@
"base64_rust\.cc": [
"+third_party/rust/chromium_crates_io/vendor/cxx-v1/include/cxx.h",
],
- "random\.cc": [
- "+absl/random/random.h",
- ],
}
diff --git a/rtc_base/random.cc b/rtc_base/random.cc
index 7f2303b..8fd23ea 100644
--- a/rtc_base/random.cc
+++ b/rtc_base/random.cc
@@ -11,21 +11,13 @@
#include <cmath>
#include <cstdint>
-#include <limits>
#include <numbers>
-#include "absl/random/random.h"
#include "rtc_base/checks.h"
#include "rtc_base/numerics/safe_conversions.h"
namespace webrtc {
-Random::Random() {
- absl::BitGen gen;
- state_ =
- absl::Uniform<uint64_t>(gen, 1, std::numeric_limits<uint64_t>::max());
-}
-
Random::Random(uint64_t seed) {
RTC_DCHECK(seed != 0x0ull);
state_ = seed;
diff --git a/rtc_base/random.h b/rtc_base/random.h
index 3b9112a..b3b9fd1 100644
--- a/rtc_base/random.h
+++ b/rtc_base/random.h
@@ -21,15 +21,20 @@
class Random {
public:
- // Returns a random number generator with a random seed.
- Random();
-
- // Returns a random number generator with the given seed. The seed must not
- // be 0. It is expected that callers intelligently generate their seeds and do
- // not simply pass a constant value or use the current time as a seed.
- // This function should only be used for testing.
+ // TODO(tommi): Change this so that the seed can be initialized internally,
+ // e.g. by offering two ways of constructing or offer a static method that
+ // returns a seed that's suitable for initialization.
+ // The problem now is that callers are calling clock_->TimeInMicroseconds()
+ // which calls TickTime::Now().Ticks(), which can return a very low value on
+ // Mac and can result in a seed of 0 after conversion to microseconds.
+ // Besides the quality of the random seed being poor, this also requires
+ // the client to take on extra dependencies to generate a seed.
+ // If we go for a static seed generator in Random, we can use something from
+ // webrtc/rtc_base and make sure that it works the same way across platforms.
+ // See also discussion here: https://codereview.webrtc.org/1623543002/
explicit Random(uint64_t seed);
+ Random() = delete;
Random(const Random&) = delete;
Random& operator=(const Random&) = delete;