// C++11 #include #include #ifdef _WIN32 #include #else #include #endif void get_time_and_set_rand_seed() { #ifdef _WIN32 FILETIME ft; GetSystemTimeAsFileTime(&ft); ULARGE_INTEGER uli; uli.LowPart = ft.dwLowDateTime; uli.HighPart = ft.dwHighDateTime; uint64_t timestamp = (uli.QuadPart - 116444736000000000ULL) / 10000000ULL; srand(timestamp % RAND_MAX); #else timeval tv; gettimeofday(&tv, nullptr); srand(tv.tv_usec); #endif }