aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Richard <[email protected]>2013-05-12 13:13:18 +0000
committerVincent Richard <[email protected]>2013-05-12 13:13:18 +0000
commit845b9ebf81775a50edff2ea45d78caa98644ea9a (patch)
treeae457fa8a6d388f548d322468c1f7ca4fc6201a9
parentAllow SPACEs at end of response line (Apple iCloud IMAP server). (diff)
downloadvmime-845b9ebf81775a50edff2ea45d78caa98644ea9a.tar.gz
vmime-845b9ebf81775a50edff2ea45d78caa98644ea9a.zip
Better random seed.
-rw-r--r--src/utility/random.cpp16
-rw-r--r--vmime/utility/random.hpp4
2 files changed, 13 insertions, 7 deletions
diff --git a/src/utility/random.cpp b/src/utility/random.cpp
index 6e96ed4e..40b27b57 100644
--- a/src/utility/random.cpp
+++ b/src/utility/random.cpp
@@ -31,16 +31,26 @@ namespace vmime {
namespace utility {
-unsigned int random::m_next(static_cast<unsigned int>(::std::time(NULL)));
+static unsigned int getRandomSeed()
+{
+ unsigned int seed;
+
+ platform::getHandler()->generateRandomBytes
+ (reinterpret_cast <unsigned char*>(&seed), sizeof(seed));
+
+ return seed;
+}
unsigned int random::getNext()
{
+ static unsigned int next = getRandomSeed();
+
// Park and Miller's minimal standard generator:
// xn+1 = (a * xn + b) mod c
// xn+1 = (16807 * xn) mod (2^31 - 1)
- m_next = static_cast<unsigned int>((16807 * m_next) % 2147483647ul);
- return (m_next);
+ next = static_cast<unsigned int>((16807 * next) % 2147483647ul);
+ return next;
}
diff --git a/vmime/utility/random.hpp b/vmime/utility/random.hpp
index ddf596b1..6c0aabf8 100644
--- a/vmime/utility/random.hpp
+++ b/vmime/utility/random.hpp
@@ -67,10 +67,6 @@ public:
*/
static const string getString(const string::size_type length, const string& randomChars
= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
-
-protected:
-
- static unsigned int m_next;
};