github.com/ledgerwatch/erigon-lib@v1.0.0/pedersen_hash/prng.h (about) 1 #ifndef STARKWARE_UTILS_PRNG_H_ 2 #define STARKWARE_UTILS_PRNG_H_ 3 4 #include <limits> 5 #include <random> 6 7 namespace starkware { 8 9 class Prng { 10 public: 11 Prng() : mt_prng_(std::random_device()()) {} 12 13 /* 14 Returns a random integer in the range [lower_bound, upper_bound]. 15 */ 16 uint64_t RandomUint64(uint64_t lower_bound, uint64_t upper_bound) { 17 return std::uniform_int_distribution<uint64_t>(lower_bound, upper_bound)(mt_prng_); 18 } 19 20 /* 21 Returns a random integer in the range [0, 2^64). 22 Note: This random number generator is NOT cryptographically secure. 23 */ 24 uint64_t RandomUint64() { return RandomUint64(0, std::numeric_limits<uint64_t>::max()); } 25 26 private: 27 std::mt19937 mt_prng_; 28 }; 29 30 } // namespace starkware 31 32 #endif // STARKWARE_UTILS_PRNG_H_