diff options
author | Aina Niemetz <aina.niemetz@gmail.com> | 2018-10-09 10:36:40 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-09 10:36:40 -0700 |
commit | 90ffa8b4eb26af9060e57be7fe5d6008717d3ce6 (patch) | |
tree | 0442e608d7cf01131cd98293a3a20b0906348c71 /src/util/random.h | |
parent | 12246d53ac1dd4bbd464dee9dea61b8ac05b4b49 (diff) |
Random: support URNG interface (#2595)
Use std::shuffle (with Random as the unified random generator) instead
of std::random_shuffle for deterministic, reproducable random shuffling.
Diffstat (limited to 'src/util/random.h')
-rw-r--r-- | src/util/random.h | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/src/util/random.h b/src/util/random.h index 480271c03..e746666fc 100644 --- a/src/util/random.h +++ b/src/util/random.h @@ -26,29 +26,40 @@ namespace CVC4 { class Random { public: - Random(uint64_t seed) { setSeed(seed); } + using result_type = uint64_t; - /* Get current RNG (singleton). */ + /** Constructor. */ + Random(uint64_t seed); + + /** Get current RNG (singleton). */ static Random& getRandom() { static thread_local Random s_current(0); return s_current; } - /* Set seed of Random. */ - void setSeed(uint64_t seed) - { - d_seed = seed == 0 ? ~seed : seed; - d_state = d_seed; - } + /** Get the minimum number that can be picked. */ + static uint64_t min() { return 0u; } + + /** Get the maximum number that can be picked. */ + static uint64_t max() { return UINT64_MAX; } + + /** Set seed of Random. */ + void setSeed(uint64_t seed); - /* Next random uint64_t number. */ + /** Operator overload to pick random uin64_t number (see rand()). */ + uint64_t operator()(); + + /** Next random uint64_t number. */ uint64_t rand(); - /* Pick random uint64_t number between from and to (inclusive). */ + + /** Pick random uint64_t number between from and to (inclusive). */ uint64_t pick(uint64_t from, uint64_t to); - /* Pick random double number between from and to (inclusive). */ + + /** Pick random double number between from and to (inclusive). */ double pickDouble(double from, double to); - /* Pick with given probability (yes / no). */ + + /** Pick with given probability (yes / no). */ bool pickWithProb(double probability); private: |