From e27a5b9a7e2d1a962fd8fd5b8da1b298cf0f1147 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Thu, 1 Aug 2013 15:47:15 +0200 Subject: [PATCH] Better srand initialization (cherry picked from commit 31e22f684fc8da83320188e5cec430e4182a9b39) --- src/common/NebulaUtil.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/common/NebulaUtil.cc b/src/common/NebulaUtil.cc index 5b43e25483..e2880c9da9 100644 --- a/src/common/NebulaUtil.cc +++ b/src/common/NebulaUtil.cc @@ -203,9 +203,16 @@ string * one_util::aes256cbc_encrypt(const string& in, const string password) string one_util::random_password() { + static bool init = false; + ostringstream sstr; - srand(time(0)); + if (!init) + { + srand(time(0) + rand()); + init = true; + } + sstr << rand(); return sha1_digest(sstr.str());