summaryrefslogtreecommitdiff
path: root/src/util/random.cpp
diff options
context:
space:
mode:
authorAina Niemetz <aina.niemetz@gmail.com>2018-10-09 10:36:40 -0700
committerGitHub <noreply@github.com>2018-10-09 10:36:40 -0700
commit90ffa8b4eb26af9060e57be7fe5d6008717d3ce6 (patch)
tree0442e608d7cf01131cd98293a3a20b0906348c71 /src/util/random.cpp
parent12246d53ac1dd4bbd464dee9dea61b8ac05b4b49 (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.cpp')
-rw-r--r--src/util/random.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/util/random.cpp b/src/util/random.cpp
index 86c569a4a..7c6abd33e 100644
--- a/src/util/random.cpp
+++ b/src/util/random.cpp
@@ -23,6 +23,16 @@
namespace CVC4 {
+Random::Random(uint64_t seed) { setSeed(seed); }
+
+void Random::setSeed(uint64_t seed)
+{
+ d_seed = seed == 0 ? ~seed : seed;
+ d_state = d_seed;
+}
+
+uint64_t Random::operator()() { return rand(); }
+
uint64_t Random::rand()
{
/* xorshift* generator (see S. Vigna, An experimental exploration of
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback