This commit is contained in:
keni
2015-04-06 08:11:17 -04:00

View File

@@ -603,24 +603,28 @@ STATIC_DCL struct tm *NDECL(getlt);
void void
setrandom() setrandom()
{ {
time_t now = getnow(); /* time((TIME_type) 0) */ unsigned long seed = getnow(); /* time((TIME_type) 0) */
#ifdef UNIX
/* Quick dirty band-aid to prevent PRNG prediction */
seed *= getpid();
#endif
/* the types are different enough here that sweeping the different /* the types are different enough here that sweeping the different
* routine names into one via #defines is even more confusing * routine names into one via #defines is even more confusing
*/ */
#ifdef RANDOM /* srandom() from sys/share/random.c */ #ifdef RANDOM /* srandom() from sys/share/random.c */
srandom((unsigned int) now); srandom((unsigned int) seed);
#else #else
# if defined(__APPLE__) || defined(BSD) || defined(LINUX) || defined(ULTRIX) || defined(CYGWIN32) /* system srandom() */ # if defined(__APPLE__) || defined(BSD) || defined(LINUX) || defined(ULTRIX) || defined(CYGWIN32) /* system srandom() */
# if defined(BSD) && !defined(POSIX_TYPES) && defined(SUNOS4) # if defined(BSD) && !defined(POSIX_TYPES) && defined(SUNOS4)
(void) (void)
# endif # endif
srandom((int) now); srandom((int) seed);
# else # else
# ifdef UNIX /* system srand48() */ # ifdef UNIX /* system srand48() */
srand48((long) now); srand48((long) seed);
# else /* poor quality system routine */ # else /* poor quality system routine */
srand((int) now); srand((int) seed);
# endif # endif
# endif # endif
#endif #endif