mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-23 18:32:55 +00:00
use arc4random() in qrand() if available
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
3a725cffb0
commit
079210cccb
2 changed files with 7 additions and 1 deletions
|
@ -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")
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue