aboutsummaryrefslogtreecommitdiff
path: root/util/random.h
diff options
context:
space:
mode:
Diffstat (limited to 'util/random.h')
-rw-r--r--util/random.h7
1 files changed, 6 insertions, 1 deletions
diff --git a/util/random.h b/util/random.h
index 0753824..ddd51b1 100644
--- a/util/random.h
+++ b/util/random.h
@@ -16,7 +16,12 @@ class Random {
private:
uint32_t seed_;
public:
- explicit Random(uint32_t s) : seed_(s & 0x7fffffffu) { }
+ explicit Random(uint32_t s) : seed_(s & 0x7fffffffu) {
+ // Avoid bad seeds.
+ if (seed_ == 0 || seed_ == 2147483647L) {
+ seed_ = 1;
+ }
+ }
uint32_t Next() {
static const uint32_t M = 2147483647L; // 2^31-1
static const uint64_t A = 16807; // bits 14, 8, 7, 5, 2, 1, 0