Skip to content
Snippets Groups Projects
Commit 29c17339 authored by rswindell's avatar rswindell
Browse files

no message

parent a6558670
No related branches found
No related tags found
No related merge requests found
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#endif /* __unix__ */ #endif /* __unix__ */
#include "genwrap.h" /* Verify prototypes */ #include "genwrap.h" /* Verify prototypes */
#include "xpendian.h" /* BYTE_SWAP */
/****************************************************************************/ /****************************************************************************/
/* Used to replace snprintf() guarantees to terminate. */ /* Used to replace snprintf() guarantees to terminate. */
...@@ -230,6 +231,28 @@ char* strrev(char* str) ...@@ -230,6 +231,28 @@ char* strrev(char* str)
} }
#endif #endif
/****************************************************************************/
/* Initialize (seed) the random number generator */
/****************************************************************************/
unsigned DLLCALL xp_randomize(void)
{
unsigned thread_id = (unsigned)GetCurrentThreadId();
unsigned process_id = (unsigned)GetCurrentProcessId();
unsigned seed = time(NULL) ^ BYTE_SWAP_INT(thread_id) ^ process_id;
#if defined(HAS_DEV_RANDOM) && defined(RANDOM_DEV)
int rf;
if((rf=open(RANDOM_DEV, O_RDONLY))!=-1) {
read(rf, &seed, sizeof(seed));
close(rf);
}
#endif
srand(seed);
return(seed);
}
/****************************************************************************/ /****************************************************************************/
/* Return random number between 0 and n-1 */ /* Return random number between 0 and n-1 */
/****************************************************************************/ /****************************************************************************/
...@@ -380,9 +403,9 @@ char* DLLCALL asctime_r(const struct tm *tm, char *buf) ...@@ -380,9 +403,9 @@ char* DLLCALL asctime_r(const struct tm *tm, char *buf)
#endif /* !defined(__unix__) */ #endif /* !defined(__unix__) */
/********************************************/ /****************************************************************/
/* Hi-res real-time clock implementation. */ /* Microsoft (DOS/Win32) real-time system clock implementation. */
/********************************************/ /****************************************************************/
#ifdef __unix__ #ifdef __unix__
clock_t DLLCALL msclock(void) clock_t DLLCALL msclock(void)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment