diff --git a/configure.ac b/configure.ac index 8d22be9..eca1811 100644 --- a/configure.ac +++ b/configure.ac @@ -106,7 +106,7 @@ dnl ## HEADERS ######################################################### dnl ############# AC_CHECK_HEADERS([ \ - sys/time.h libgen.h paths.h \ + sys/random.h sys/time.h libgen.h paths.h \ ], [], [], [ #ifdef HAVE_SYS_TYPES_H @@ -172,7 +172,7 @@ dnl ####################### AC_CHECK_FUNCS([ \ arc4random \ - srandomdev \ + getrandom \ ]) AC_REPLACE_FUNCS([ \ diff --git a/src/playlist.c b/src/playlist.c index 5e2f659..87e27ad 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -19,6 +19,9 @@ #endif #include +#ifdef HAVE_SYS_RANDOM_H +# include +#endif #include #include @@ -98,10 +101,14 @@ _playlist_random(void) #ifdef HAVE_ARC4RANDOM ret = arc4random(); -#elif HAVE_RANDOM - ret = (unsigned int)random(); +#elif HAVE_GETRANDOM + if (sizeof(ret) != getrandom(&ret, sizeof(ret), 0)) { + log_alert("getrandom: %s", strerror(errno)); + exit(1); + } #else - ret = (unsigned int)rand(); +# warning "using deterministic randomness for shuffling playlists" + ret = (unsigned int)random(); #endif return (ret); @@ -157,15 +164,8 @@ _playlist_run_program(struct playlist *pl) int playlist_init(void) { -#ifdef HAVE_RANDOM -# ifdef HAVE_SRANDOMDEV - srandomdev(); -# else srandom((unsigned int)time(NULL)); -# endif /* HAVE_SRANDOMDEV */ -#else - srand((unsigned int)time(NULL)); -#endif /* HAVE_RANDOM */ + return (0); }