]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/rocksdb/util/random.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / rocksdb / util / random.h
index f97b2126f35bacc5cc63085f405286a619a5eab6..5f6eaf51ef38f7ee894c85b231640a962c415d3f 100644 (file)
@@ -9,6 +9,7 @@
 
 #pragma once
 #include <stdint.h>
+#include <algorithm>
 #include <random>
 
 #include "rocksdb/rocksdb_namespace.h"
@@ -85,6 +86,12 @@ class Random {
     return Uniform(1 << Uniform(max_log + 1));
   }
 
+  // Returns a random string of length "len"
+  std::string RandomString(int len);
+
+  // Generates a random string of len bytes using human-readable characters
+  std::string HumanReadableString(int len);
+
   // Returns a Random instance for use by the current thread without
   // additional locking
   static Random* GetTLSInstance();
@@ -163,4 +170,17 @@ class Random64 {
   }
 };
 
+// A seeded replacement for removed std::random_shuffle
+template <class RandomIt>
+void RandomShuffle(RandomIt first, RandomIt last, uint32_t seed) {
+  std::mt19937 rng(seed);
+  std::shuffle(first, last, rng);
+}
+
+// A replacement for removed std::random_shuffle
+template <class RandomIt>
+void RandomShuffle(RandomIt first, RandomIt last) {
+  RandomShuffle(first, last, std::random_device{}());
+}
+
 }  // namespace ROCKSDB_NAMESPACE