summaryrefslogtreecommitdiff
path: root/src/util/random.h
diff options
context:
space:
mode:
authorAina Niemetz <aina.niemetz@gmail.com>2017-12-29 18:08:41 -0800
committerGitHub <noreply@github.com>2017-12-29 18:08:41 -0800
commit2d147b72e1339f4c281caf7786dfa9b4d79ed21c (patch)
treef4b2d78feea05ccbf4ff774d1c9bd3c6f473d9dd /src/util/random.h
parent47d542f312ac8e22e8d3aae1007cfd13701983a6 (diff)
Fix RNG for seed = 0. (#1459)
The default value for the seed for CVC4's RNG is 0. However, xorshift* requires a non-zero seed, else it generates only zero values. This fixes and prevents this behavior by resetting a given zero seed to ~0.
Diffstat (limited to 'src/util/random.h')
-rw-r--r--src/util/random.h6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/util/random.h b/src/util/random.h
index 9083c63e4..1e837642e 100644
--- a/src/util/random.h
+++ b/src/util/random.h
@@ -28,7 +28,7 @@ namespace CVC4 {
class Random
{
public:
- Random(uint64_t seed) : d_seed(seed), d_state(seed) {}
+ Random(uint64_t seed) { setSeed(seed); }
/* Get current RNG (singleton). */
static Random& getRandom()
@@ -40,8 +40,8 @@ class Random
/* Set seed of Random. */
void setSeed(uint64_t seed)
{
- d_seed = seed;
- d_state = seed;
+ d_seed = seed == 0 ? ~seed : seed;
+ d_state = d_seed;
}
/* Next random uint64_t number. */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback