diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index 46e11566..5a7395db 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -43,9 +43,10 @@ kde4_bool_to_01(X11_XSync_FOUND HAVE_XSYNC) # kidletim check_symbol_exists(strtoll "stdlib.h" HAVE_STRTOLL) # kioslave check_symbol_exists(getgrouplist "unistd.h;grp.h" HAVE_GETGROUPLIST) # kio -check_function_exists(backtrace HAVE_BACKTRACE) # kdecore, kio -check_function_exists(fdatasync HAVE_FDATASYNC) # kdecore -check_function_exists(sendfile HAVE_SENDFILE) # kioslave +check_function_exists(backtrace HAVE_BACKTRACE) # kdecore, kio +check_function_exists(fdatasync HAVE_FDATASYNC) # kdecore +check_function_exists(arc4random_uniform HAVE_ARC4RANDOM_UNIFORM) # kdecore +check_function_exists(sendfile HAVE_SENDFILE) # kioslave check_library_exists(socket connect "" HAVE_SOCKET_LIBRARY) # kinit diff --git a/config.h.cmake b/config.h.cmake index 037fd474..a4f6ecee 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -17,6 +17,7 @@ #cmakedefine HAVE_BACKTRACE 1 #cmakedefine HAVE_GETMNTINFO 1 #cmakedefine HAVE_FDATASYNC 1 +#cmakedefine HAVE_ARC4RANDOM_UNIFORM 1 #cmakedefine HAVE_SENDFILE 1 #cmakedefine HAVE_SETMNTENT 1 #cmakedefine HAVE_STRTOLL 1 diff --git a/kdecore/util/krandom.cpp b/kdecore/util/krandom.cpp index 4363130a..713787d2 100644 --- a/kdecore/util/krandom.cpp +++ b/kdecore/util/krandom.cpp @@ -16,9 +16,14 @@ Boston, MA 02110-1301, USA. */ +#include "config.h" #include "krandom.h" #include "kdebug.h" +#if defined(HAVE_ARC4RANDOM_UNIFORM) +# include +#endif + int KRandom::randomMax(int max) { if (Q_UNLIKELY(max <= 0)) { @@ -26,7 +31,11 @@ int KRandom::randomMax(int max) return 0; } +#if defined(HAVE_ARC4RANDOM_UNIFORM) + return ::arc4random_uniform(max); +#else return KRandom::random() % max; +#endif } QString KRandom::randomString(int length)