diff options
-rw-r--r-- | src/H5.c | 21 | ||||
-rw-r--r-- | src/H5private.h | 18 |
2 files changed, 23 insertions, 16 deletions
@@ -3119,12 +3119,11 @@ H5_trace (const double *returning, const char *func, const char *type, ...) * Function: HDrand/HDsrand * * Purpose: Wrapper function for rand. If rand_r exists on this system, - * use it. Otherwise, just call random() or rand(). + * use it. * * Wrapper function for srand. If rand_r is available, it will keep * track of the seed locally instead of using srand() which modifies - * global state and can break other programs. Otherwise, just call - * srandom() or srand(). + * global state and can break other programs. * * Return: Success: Random number from 0 to RAND_MAX * @@ -3136,26 +3135,18 @@ H5_trace (const double *returning, const char *func, const char *type, ...) * Modifications: *------------------------------------------------------------------------- */ +#ifdef H5_HAVE_RAND_R + static unsigned int g_seed = 42; int HDrand(void) { -#ifdef H5_HAVE_RAND_R return rand_r(&g_seed); -#elif H5_HAVE_RANDOM - return random(); -#else - return rand(); -#endif } void HDsrand(unsigned int seed) { -#ifdef H5_HAVE_RAND_R g_seed = seed; -#elif H5_HAVE_RANDOM - srandom(seed); -#else - srand(seed); -#endif } + +#endif diff --git a/src/H5private.h b/src/H5private.h index 96e91eb..b89967d 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -773,8 +773,24 @@ typedef off_t h5_stat_size_t; #define HDputs(S) puts(S) #define HDqsort(M,N,Z,F) qsort(M,N,Z,F) #define HDraise(N) raise(N) -H5_DLL int HDrand(void); + +#ifdef H5_HAVE_RAND_R #define HDrandom() HDrand() +#define HDsrandom(S) HDsrand(S) +H5_DLL int HDrand(); +H5_DLL void HDsrand(unsigned int seed); +#elif H5_HAVE_RANDOM +#define HDrand() random() +#define HDrandom() random() +#define HDsrandom(S) srandom(S) +#define HDsrand(S) srandom(S) +#else +#define HDrand() rand() +#define HDrandom() rand() +#define HDsrandom(S) srand(S) +#define HDsrand(S) srand(S) +#endif + #define HDread(F,M,Z) read(F,M,Z) #define HDreaddir(D) readdir(D) #define HDrealloc(M,Z) realloc(M,Z) |