diff --git a/ChangeLog b/ChangeLog index 234fb26..6d28237 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2006-07-23 Sheplyakov Alexei + + * src/base/random/cl_random_from.cc: Add support for MinGW. + 2006-06-13 Richard B. Kreckel * m4/general.m4 (CL_CANONICAL_HOST_CPU): Force host_cpu=i386 for x86_64 diff --git a/src/base/random/cl_random_from.cc b/src/base/random/cl_random_from.cc index 6c3b123..0470a4e 100644 --- a/src/base/random/cl_random_from.cc +++ b/src/base/random/cl_random_from.cc @@ -9,14 +9,18 @@ // Implementation. +#if defined(_WIN32) +#include // for GetCurrentProcessId() +#endif + #include "cl_base_config.h" #include "cl_low.h" +#include // declares rand() -#if defined(unix) || defined(__unix) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(_AIX) || defined(sinix) || (defined(__MACH__) && defined(__APPLE__)) || (defined(_WIN32) && defined(__GNUC__)) || defined(__BEOS__) +#if defined(unix) || defined(__unix) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(_AIX) || defined(sinix) || (defined(__MACH__) && defined(__APPLE__)) || (defined(__CYGWIN__) && defined(__GNUC__)) || defined(__BEOS__) #include #include // declares getpid() -#include // declares rand() #if defined(HAVE_GETTIMEOFDAY) @@ -43,15 +47,30 @@ inline uint32 get_seed (void) #include extern "C" clock_t times (struct tms * buffer); +namespace cln { inline uint32 get_seed (void) { var struct tms tmsbuf; var uint32 seed_lo = times(&tmsbuf); return seed_lo + tmsbuf.tms_utime + tmsbuf.tms_stime; } +} // namespace cln #endif +#elif defined(_WIN32) +#include +#include + +namespace cln { +inline uint32 get_seed (void) +{ + struct timeb timebuf; + ftime(&timebuf); + return cln::highlow32(timebuf.time, (long)(timebuf.millitm)*1000); +} +} // namespace cln + #endif namespace cln { @@ -64,13 +83,16 @@ random_state::random_state () { var uint32 seed_hi; var uint32 seed_lo; -#if defined(unix) || defined(__unix) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(_AIX) || defined(sinix) || (defined(__MACH__) && defined(__APPLE__)) || (defined(_WIN32) && defined(__GNUC__)) || defined(__BEOS__) +#if defined(unix) || defined(__unix) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(_AIX) || defined(sinix) || (defined(__MACH__) && defined(__APPLE__)) || (defined(__CYGWIN__) && defined(__GNUC__)) || defined(__BEOS__) seed_lo = ::get_seed(); seed_hi = (rand() // zufällige 31 Bit (bei UNIX_BSD) bzw. 16 Bit (bei UNIX_SYSV) << 8) ^ (uintL)(getpid()); // ca. 8 Bit von der Process ID #elif defined(__OpenBSD__) seed_lo = arc4random(); seed_hi = arc4random(); +#elif defined(_WIN32) + seed_lo = ::get_seed(); + seed_hi = (rand() << 8) ^ (uintL)(GetCurrentProcessId()); #elif defined(__atarist) seed_lo = highlow32(GEMDOS_GetDate(),GEMDOS_GetTime()); // 16+16 zufällige Bits seed_hi = XBIOS_Random(); // 24 Bit zufällig vom XBIOS, vorne 8 Nullbits