diff --git a/qrtplib/rtprandom.cpp b/qrtplib/rtprandom.cpp index 035c6d2b9..5fbb5562f 100644 --- a/qrtplib/rtprandom.cpp +++ b/qrtplib/rtprandom.cpp @@ -38,18 +38,11 @@ #include "rtprandomrands.h" #include "rtprandomurandom.h" #include "rtprandomrand48.h" + #include -#ifndef WIN32 #include -#else -#ifndef _WIN32_WCE -#include -#else -#include -#include -#endif // _WIN32_WINCE -#include -#endif // WIN32 + +#include namespace qrtplib { @@ -57,39 +50,21 @@ namespace qrtplib uint32_t RTPRandom::PickSeed() { uint32_t x; -#if defined(WIN32) || defined(_WIN32_WINCE) -#ifndef _WIN32_WCE - x = (uint32_t)_getpid(); - x += (uint32_t)time(0); - x += (uint32_t)clock(); -#else - x = (uint32_t)GetCurrentProcessId(); - - FILETIME ft; - SYSTEMTIME st; - - GetSystemTime(&st); - SystemTimeToFileTime(&st,&ft); - - x += ft.dwLowDateTime; -#endif // _WIN32_WCE - x ^= (uint32_t)((uint8_t *)this - (uint8_t *)0); -#else x = (uint32_t) getpid(); - x += (uint32_t) time(0); - x += (uint32_t) clock(); - x ^= (uint32_t) ((uint8_t *) this - (uint8_t *) 0); + QDateTime currentDateTime = QDateTime::currentDateTime(); + x += currentDateTime.toTime_t(); +#if defined(WIN32) + x += QDateTime::currentMSecsSinceEpoch() % 1000; +#else + x += (uint32_t)clock(); #endif + x ^= (uint32_t)((uint8_t *)this - (uint8_t *)0); return x; } RTPRandom *RTPRandom::CreateDefaultRandomNumberGenerator() { -#ifdef RTP_HAVE_RAND_S - RTPRandomRandS *r = new RTPRandomRandS(); -#else RTPRandomURandom *r = new RTPRandomURandom(); -#endif // RTP_HAVE_RAND_S RTPRandom *rRet = r; if (r->Init() < 0) // fall back to rand48 diff --git a/qrtplib/rtprandomrand48.cpp b/qrtplib/rtprandomrand48.cpp index 73f8a9e87..c80ccf6aa 100644 --- a/qrtplib/rtprandomrand48.cpp +++ b/qrtplib/rtprandomrand48.cpp @@ -51,12 +51,7 @@ RTPRandomRand48::~RTPRandomRand48() void RTPRandomRand48::SetSeed(uint32_t seed) { - -#ifdef RTP_HAVE_VSUINT64SUFFIX - state = ((uint64_t)seed) << 16 | 0x330Eui64; -#else state = ((uint64_t) seed) << 16 | 0x330EULL; -#endif // RTP_HAVE_VSUINT64SUFFIX } uint8_t RTPRandomRand48::GetRandom8() @@ -75,16 +70,8 @@ uint16_t RTPRandomRand48::GetRandom16() uint32_t RTPRandomRand48::GetRandom32() { - -#ifdef RTP_HAVE_VSUINT64SUFFIX - state = ((0x5DEECE66Dui64*state) + 0xBui64)&0x0000ffffffffffffui64; - - uint32_t x = (uint32_t)((state>>16)&0xffffffffui64); -#else state = ((0x5DEECE66DULL * state) + 0xBULL) & 0x0000ffffffffffffULL; - uint32_t x = (uint32_t) ((state >> 16) & 0xffffffffULL); -#endif // RTP_HAVE_VSUINT64SUFFIX return x; } @@ -92,15 +79,8 @@ uint32_t RTPRandomRand48::GetRandom32() double RTPRandomRand48::GetRandomDouble() { -#ifdef RTP_HAVE_VSUINT64SUFFIX - state = ((0x5DEECE66Dui64*state) + 0xBui64)&0x0000ffffffffffffui64; - - int64_t x = (int64_t)state; -#else state = ((0x5DEECE66DULL * state) + 0xBULL) & 0x0000ffffffffffffULL; - int64_t x = (int64_t) state; -#endif // RTP_HAVE_VSUINT64SUFFIX double y = 3.552713678800500929355621337890625e-15 * (double) x; return y; diff --git a/qrtplib/rtprandomurandom.cpp b/qrtplib/rtprandomurandom.cpp index dc4512f1a..b96b5c6cf 100644 --- a/qrtplib/rtprandomurandom.cpp +++ b/qrtplib/rtprandomurandom.cpp @@ -116,17 +116,11 @@ double RTPRandomURandom::GetRandomDouble() return 0; } -#ifdef RTP_HAVE_VSUINT64SUFFIX - value &= 0x7fffffffffffffffui64; -#else value &= 0x7fffffffffffffffULL; -#endif // RTP_HAVE_VSUINT64SUFFIX - int64_t value2 = (int64_t) value; double x = RTPRANDOM_2POWMIN63 * (double) value2; return x; - } } // end namespace