diff --git a/CMakeLists.txt b/CMakeLists.txt index e42302efe..10f4307bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -374,6 +374,8 @@ katie_check_function(ecvt "stdlib.h") katie_check_function(getprogname "stdlib.h") # FreeBSD 5.4 katie_check_function(pthread_attr_get_np "pthread_np.h" "${CMAKE_THREAD_LIBS_INIT}") +# OpenBSD 2.1 +katie_check_function(arc4random "stdlib.h") # GNU katie_check_function(get_current_dir_name "unistd.h") katie_check_function(prctl "sys/prctl.h") diff --git a/src/core/global/qglobal.cpp b/src/core/global/qglobal.cpp index e01287ada..3bd5eb59e 100644 --- a/src/core/global/qglobal.cpp +++ b/src/core/global/qglobal.cpp @@ -1523,14 +1523,18 @@ void qsrand(uint seed) \sa qsrand() */ -thread_local time_t almostrandom = 0; int qrand() { +#if defined(QT_HAVE_ARC4RANDOM) + return ::arc4random(); +#else // Seed the PRNG once per thread with a combination of current time and its address + thread_local time_t almostrandom = 0; if (!almostrandom) { ::time(&almostrandom); std::srand(almostrandom + std::intptr_t(&almostrandom)); } +#endif return std::rand(); }