Make SimpleRandom faster by using Chacha20 as underlying primitive.

This does alter the output of the RNG, but that's a one-time cost, and one SHA-1 call per byte is highly suboptimal for anything but very short unit tests.

gfe-relnote: n/a (test-only change)
PiperOrigin-RevId: 245501012
Change-Id: I16d9f5b174ef65cfb4ece3ef0699bf1b29b81de5
diff --git a/quic/test_tools/quic_test_utils.h b/quic/test_tools/quic_test_utils.h
index 57831ab..c9db3e5 100644
--- a/quic/test_tools/quic_test_utils.h
+++ b/quic/test_tools/quic_test_utils.h
@@ -213,12 +213,10 @@
 std::string Sha1Hash(QuicStringPiece data);
 
 // Simple random number generator used to compute random numbers suitable
-// for pseudo-randomly dropping packets in tests.  It works by computing
-// the sha1 hash of the current seed, and using the first 64 bits as
-// the next random number, and the next seed.
+// for pseudo-randomly dropping packets in tests.
 class SimpleRandom : public QuicRandom {
  public:
-  SimpleRandom() : seed_(0) {}
+  SimpleRandom() { set_seed(0); }
   SimpleRandom(const SimpleRandom&) = delete;
   SimpleRandom& operator=(const SimpleRandom&) = delete;
   ~SimpleRandom() override {}
@@ -228,10 +226,14 @@
 
   void RandBytes(void* data, size_t len) override;
 
-  void set_seed(uint64_t seed) { seed_ = seed; }
+  void set_seed(uint64_t seed);
 
  private:
-  uint64_t seed_;
+  uint8_t buffer_[4096];
+  size_t buffer_offset_;
+  uint8_t key_[32];
+
+  void FillBuffer();
 };
 
 class MockFramerVisitor : public QuicFramerVisitorInterface {