5 #ifndef V8_BASE_UTILS_RANDOM_NUMBER_GENERATOR_H_ 6 #define V8_BASE_UTILS_RANDOM_NUMBER_GENERATOR_H_ 8 #include <unordered_set> 11 #include "src/base/base-export.h" 12 #include "src/base/macros.h" 42 typedef bool (*EntropySource)(
unsigned char* buffer,
size_t buflen);
43 static void SetEntropySource(EntropySource entropy_source);
53 V8_INLINE
int NextInt() V8_WARN_UNUSED_RESULT {
return Next(32); }
61 int NextInt(
int max) V8_WARN_UNUSED_RESULT;
68 V8_INLINE
bool NextBool() V8_WARN_UNUSED_RESULT {
return Next(1) != 0; }
75 double NextDouble() V8_WARN_UNUSED_RESULT;
82 int64_t NextInt64() V8_WARN_UNUSED_RESULT;
85 void NextBytes(
void* buffer,
size_t buflen);
90 std::vector<uint64_t> NextSample(uint64_t max,
91 size_t n) V8_WARN_UNUSED_RESULT;
100 std::vector<uint64_t> NextSampleSlow(
101 uint64_t max,
size_t n,
102 const std::unordered_set<uint64_t>& excluded =
103 std::unordered_set<uint64_t>{}) V8_WARN_UNUSED_RESULT;
108 int64_t initial_seed()
const {
return initial_seed_; }
111 static inline double ToDouble(uint64_t state0) {
113 static const uint64_t kExponentBits = uint64_t{0x3FF0000000000000};
114 uint64_t random = (state0 >> 12) | kExponentBits;
115 return bit_cast<
double>(random) - 1;
119 static inline void XorShift128(uint64_t* state0, uint64_t* state1) {
120 uint64_t s1 = *state0;
121 uint64_t s0 = *state1;
130 static uint64_t MurmurHash3(uint64_t);
133 static const int64_t kMultiplier = V8_2PART_UINT64_C(0x5, deece66d);
134 static const int64_t kAddend = 0xb;
135 static const int64_t kMask = V8_2PART_UINT64_C(0xffff, ffffffff);
137 int Next(
int bits) V8_WARN_UNUSED_RESULT;
147 #endif // V8_BASE_UTILS_RANDOM_NUMBER_GENERATOR_H_