diff --git a/config/cmake/ConfigureChecks.cmake b/config/cmake/ConfigureChecks.cmake index 4d27d662a65..15d96f607fb 100644 --- a/config/cmake/ConfigureChecks.cmake +++ b/config/cmake/ConfigureChecks.cmake @@ -408,8 +408,6 @@ CHECK_FUNCTION_EXISTS (getrusage ${HDF_PREFIX}_HAVE_GETRUSAGE) CHECK_FUNCTION_EXISTS (pread ${HDF_PREFIX}_HAVE_PREAD) CHECK_FUNCTION_EXISTS (pwrite ${HDF_PREFIX}_HAVE_PWRITE) -CHECK_FUNCTION_EXISTS (rand_r ${HDF_PREFIX}_HAVE_RAND_R) -CHECK_FUNCTION_EXISTS (random ${HDF_PREFIX}_HAVE_RANDOM) CHECK_FUNCTION_EXISTS (strcasestr ${HDF_PREFIX}_HAVE_STRCASESTR) CHECK_FUNCTION_EXISTS (strdup ${HDF_PREFIX}_HAVE_STRDUP) diff --git a/config/cmake/H5pubconf.h.in b/config/cmake/H5pubconf.h.in index b3fbede50a3..586032bf269 100644 --- a/config/cmake/H5pubconf.h.in +++ b/config/cmake/H5pubconf.h.in @@ -276,12 +276,6 @@ /* Define to 1 if you have the header file. */ #cmakedefine H5_HAVE_QUADMATH_H @H5_HAVE_QUADMATH_H@ -/* Define to 1 if you have the `random' function. */ -#cmakedefine H5_HAVE_RANDOM @H5_HAVE_RANDOM@ - -/* Define to 1 if you have the `rand_r' function. */ -#cmakedefine H5_HAVE_RAND_R @H5_HAVE_RAND_R@ - /* Define whether the Read-Only S3 virtual file driver (VFD) should be compiled */ #cmakedefine H5_HAVE_ROS3_VFD @H5_HAVE_ROS3_VFD@ diff --git a/configure.ac b/configure.ac index 5fb3718ef1e..b22c8ea21a4 100644 --- a/configure.ac +++ b/configure.ac @@ -2393,7 +2393,6 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ AC_SEARCH_LIBS([clock_gettime], [rt posix4]) AC_CHECK_FUNCS([asprintf clock_gettime fcntl flock fork]) AC_CHECK_FUNCS([gethostname getrusage gettimeofday]) -AC_CHECK_FUNCS([rand_r random]) AC_CHECK_FUNCS([strcasestr strdup symlink]) AC_CHECK_FUNCS([tmpfile vasprintf waitpid]) diff --git a/src/H5private.h b/src/H5private.h index e0148f43d70..d06e950e7e4 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -786,46 +786,6 @@ H5_DLL H5_ATTR_CONST int Nflock(int fd, int operation); #ifndef HDpwrite #define HDpwrite(F, B, C, O) pwrite(F, B, C, O) #endif - -/* clang-format off */ -#ifdef H5_HAVE_RAND_R -# ifndef HDrandom -# define HDrandom() HDrand() -# endif - H5_DLL int HDrand(void); -# ifndef HDsrandom -# define HDsrandom(S) HDsrand(S) -# endif - H5_DLL void HDsrand(unsigned int seed); -#elif defined(H5_HAVE_RANDOM) -# ifndef HDrand -# define HDrand() random() -# endif -# ifndef HDrandom -# define HDrandom() random() -# endif -# ifndef HDsrand -# define HDsrand(S) srandom(S) -# endif -# ifndef HDsrandom -# define HDsrandom(S) srandom(S) -# endif -#else -# ifndef HDrand -# define HDrand() rand() -# endif -# ifndef HDrandom -# define HDrandom() rand() -# endif -# ifndef HDsrand -# define HDsrand(S) srand(S) -# endif -# ifndef HDsrandom -# define HDsrandom(S) srand(S) -# endif -#endif -/* clang-format on */ - #ifndef HDread #define HDread(F, M, Z) read(F, M, Z) #endif diff --git a/src/H5system.c b/src/H5system.c index 1379fa7dc95..a60cc59e5d5 100644 --- a/src/H5system.c +++ b/src/H5system.c @@ -93,39 +93,6 @@ HDvasprintf(char **bufp, const char *fmt, va_list _ap) } #endif /* H5_HAVE_VASPRINTF */ -/*------------------------------------------------------------------------- - * Function: HDrand/HDsrand - * - * Purpose: Wrapper function for rand. If rand_r exists on this system, - * 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. - * - * Return: Success: Random number from 0 to RAND_MAX - * - * Failure: Cannot fail. - * - *------------------------------------------------------------------------- - */ -#ifdef H5_HAVE_RAND_R - -static unsigned int g_seed = 42; - -int -HDrand(void) -{ - return rand_r(&g_seed); -} - -void -HDsrand(unsigned int seed) -{ - g_seed = seed; -} -#endif /* H5_HAVE_RAND_R */ - /*------------------------------------------------------------------------- * Function: Pflock * diff --git a/test/accum.c b/test/accum.c index ac9754bf4b9..d5b308dad06 100644 --- a/test/accum.c +++ b/test/accum.c @@ -1925,7 +1925,7 @@ test_random_write(H5F_t *f) /* seed = (unsigned)1155438845; */ fprintf(stderr, "Random # seed was: %u\n", seed); #endif - HDsrandom(seed); + srand(seed); /* Allocate space for the segment length buffer */ off = (size_t *)malloc(MAX_RANDOM_SEGMENTS * sizeof(size_t)); @@ -1940,8 +1940,8 @@ fprintf(stderr, "Random # seed was: %u\n", seed); /* Choose random length of segment, allowing for variance */ do { - length += (size_t)(HDrandom() % RAND_SEG_LEN) + 1; - } while ((HDrandom() & 256) >= 128); /* end while */ + length += (size_t)(rand() % RAND_SEG_LEN) + 1; + } while ((rand() & 256) >= 128); /* end while */ /* Check for going off end of buffer */ if ((cur_off + length) > RANDOM_BUF_SIZE) @@ -1972,7 +1972,7 @@ fprintf(stderr, "Random # seed was: %u\n", seed); size_t tmp; /* Temporary holder for offset & length values */ /* Choose value within next few elements to to swap with */ - swap = ((size_t)HDrandom() % 8) + u; + swap = ((size_t)rand() % 8) + u; if (swap >= nsegments) swap = nsegments - 1; diff --git a/test/app_ref.c b/test/app_ref.c index 7c4fe3e0f50..2f093981d9c 100644 --- a/test/app_ref.c +++ b/test/app_ref.c @@ -27,7 +27,7 @@ * 1 to MAX_NINC). Assumes integers i and ninc are in scope. */ #define RAND_INC(id) \ do { \ - ninc = (HDrand() % MAX_NINC) + 1; \ + ninc = (rand() % MAX_NINC) + 1; \ \ for (i = 0; i < ninc; i++) \ if (H5Iinc_ref(ids[id]) != i + 2) \ @@ -89,7 +89,7 @@ main(void) h5_reset(); h5_fixname(FILENAME[0], H5P_DEFAULT, filename, sizeof filename); - HDsrand((unsigned)time(NULL)); + srand((unsigned)time(NULL)); TESTING("library shutdown with reference count > 1"); diff --git a/test/big.c b/test/big.c index cf8a3f2ef38..508cd82469f 100644 --- a/test/big.c +++ b/test/big.c @@ -103,8 +103,8 @@ randll(hsize_t limit, int current_index) /* Generate up to MAX_TRIES random numbers until one of them */ /* does not overlap with any previous writes */ while (overlap != 0 && tries < MAX_TRIES) { - acc = (hsize_t)HDrandom(); - acc *= (hsize_t)HDrandom(); + acc = (hsize_t)rand(); + acc *= (hsize_t)rand(); acc = acc % limit; overlap = 0; @@ -757,7 +757,7 @@ main(int ac, char **av) /* seed = (unsigned long)1155438845; */ fprintf(stderr, "Random # seed was: %lu\n", seed); #endif - HDsrandom((unsigned)seed); + srand((unsigned)seed); /* run VFD-specific test */ if (H5FD_SEC2 == driver) { diff --git a/test/bittests.c b/test/bittests.c index df4273792b1..643964efea4 100644 --- a/test/bittests.c +++ b/test/bittests.c @@ -156,9 +156,9 @@ test_copy(void) TESTING("bit copy operations"); for (i = 0; i < NTESTS; i++) { - s_offset = (size_t)HDrand() % (8 * sizeof v1); - d_offset = (size_t)HDrand() % (8 * sizeof v2); - size = (unsigned)HDrand() % MIN(8 * sizeof(v1), 8 * sizeof(v2)); + s_offset = (size_t)rand() % (8 * sizeof v1); + d_offset = (size_t)rand() % (8 * sizeof v2); + size = (unsigned)rand() % MIN(8 * sizeof(v1), 8 * sizeof(v2)); size = MIN3(size, 8 * sizeof(v1) - s_offset, 8 * sizeof(v2) - d_offset); memset(v1, 0xff, sizeof v1); memset(v2, 0x00, sizeof v2); @@ -277,12 +277,12 @@ test_shift(void) TESTING("bit shift operations"); for (i = 0; i < NTESTS; i++) { - offset = (size_t)HDrand() % (8 * sizeof vector); - size = (size_t)HDrand() % (8 * sizeof(vector) - offset); + offset = (size_t)rand() % (8 * sizeof vector); + size = (size_t)rand() % (8 * sizeof(vector) - offset); /* Don't want size to be 0 */ if (size == 0) continue; - shift_dist = (ssize_t)((size_t)HDrand() % size); + shift_dist = (ssize_t)((size_t)rand() % size); /*-------- LEFT-shift some bits and make sure something was shifted --------*/ memset(vector, 0x00, sizeof vector); @@ -411,8 +411,8 @@ test_increment(void) TESTING("bit increment operations"); for (i = 0; i < NTESTS; i++) { - offset = (size_t)HDrand() % (8 * sizeof vector); - size = (size_t)HDrand() % (8 * sizeof(vector) - offset); + offset = (size_t)rand() % (8 * sizeof vector); + size = (size_t)rand() % (8 * sizeof(vector) - offset); /* Don't want size to be 0 */ if (size == 0) continue; @@ -497,8 +497,8 @@ test_decrement(void) TESTING("bit decrement operations"); for (i = 0; i < NTESTS; i++) { - offset = (size_t)HDrand() % (8 * sizeof vector); - size = (size_t)HDrand() % (8 * sizeof(vector) - offset); + offset = (size_t)rand() % (8 * sizeof vector); + size = (size_t)rand() % (8 * sizeof(vector) - offset); /* Don't want size to be 0 */ if (size == 0) continue; @@ -566,8 +566,8 @@ test_negate(void) TESTING("bit negate operations"); for (i = 0; i < NTESTS; i++) { - offset = (size_t)HDrand() % (8 * sizeof vector); - size = (size_t)HDrand() % (8 * sizeof(vector) - offset); + offset = (size_t)rand() % (8 * sizeof vector); + size = (size_t)rand() % (8 * sizeof(vector) - offset); /* Don't want size to be 0 */ if (size == 0) continue; @@ -665,8 +665,8 @@ test_set(void) TESTING("bit set operations"); for (i = 0; i < NTESTS; i++) { - d_offset = (size_t)HDrand() % (8 * sizeof v2); - size = (size_t)HDrand() % (8 * sizeof(v2)); + d_offset = (size_t)rand() % (8 * sizeof v2); + size = (size_t)rand() % (8 * sizeof(v2)); size = MIN(size, 8 * sizeof(v2) - d_offset); memset(v2, 0x00, sizeof v2); @@ -780,8 +780,8 @@ test_clear(void) TESTING("bit clear operations"); for (i = 0; i < NTESTS; i++) { - d_offset = (size_t)HDrand() % (8 * sizeof v2); - size = (size_t)HDrand() % (8 * sizeof(v2)); + d_offset = (size_t)rand() % (8 * sizeof v2); + size = (size_t)rand() % (8 * sizeof(v2)); size = MIN(size, 8 * sizeof(v2) - d_offset); memset(v2, 0xff, sizeof v2); diff --git a/test/btree2.c b/test/btree2.c index a44a2475732..1bf25e9400f 100644 --- a/test/btree2.c +++ b/test/btree2.c @@ -2908,7 +2908,7 @@ test_insert_lots(hid_t fapl, const H5B2_create_t *cparam, const bt2_test_param_t curr_time=1109170019; fprintf(stderr,"curr_time=%lu\n",(unsigned long)curr_time); #endif - HDsrandom((unsigned)curr_time); + srand((unsigned)curr_time); /* * Test inserting many records into v2 B-tree @@ -2925,7 +2925,7 @@ fprintf(stderr,"curr_time=%lu\n",(unsigned long)curr_time); /* Shuffle record #'s */ for (u = 0; u < INSERT_MANY; u++) { - swap_idx = ((unsigned)HDrandom() % (INSERT_MANY - u)) + u; + swap_idx = ((unsigned)rand() % (INSERT_MANY - u)) + u; temp_rec = records[u]; records[u] = records[swap_idx]; records[swap_idx] = temp_rec; @@ -3015,7 +3015,7 @@ fprintf(stderr,"curr_time=%lu\n",(unsigned long)curr_time); /* Find random records */ for (u = 0; u < FIND_MANY; u++) { /* Pick random record */ - idx = (hsize_t)(HDrandom() % INSERT_MANY); + idx = (hsize_t)(rand() % INSERT_MANY); /* Attempt to find existent record in root of level-4 B-tree */ found = false; @@ -3046,7 +3046,7 @@ fprintf(stderr,"curr_time=%lu\n",(unsigned long)curr_time); /* Find random records */ for (u = 0; u < FIND_MANY; u++) { /* Pick random record */ - idx = (hsize_t)(HDrandom() % INSERT_MANY); + idx = (hsize_t)(rand() % INSERT_MANY); /* Attempt to find existent record in root of level-4 B-tree */ /* (in increasing order) */ @@ -4978,7 +4978,7 @@ test_update_lots(hid_t fapl, const H5B2_create_t *cparam, const bt2_test_param_t curr_time = 1451342093; fprintf(stderr, "curr_time = %lu\n", (unsigned long)curr_time); #endif - HDsrandom((unsigned)curr_time); + srand((unsigned)curr_time); /* * Test inserting many records into v2 B-tree @@ -5000,7 +5000,7 @@ fprintf(stderr, "curr_time = %lu\n", (unsigned long)curr_time); H5B2_test_rec_t temp_rec; /* Temporary record */ unsigned swap_idx; /* Location to swap with when shuffling */ - swap_idx = ((unsigned)HDrandom() % (INSERT_MANY_REC - u)) + u; + swap_idx = ((unsigned)rand() % (INSERT_MANY_REC - u)) + u; temp_rec = records[u]; records[u] = records[swap_idx]; records[swap_idx] = temp_rec; @@ -5076,7 +5076,7 @@ fprintf(stderr, "curr_time = %lu\n", (unsigned long)curr_time); /* Find random records */ for (u = 0; u < FIND_MANY_REC; u++) { /* Pick random record */ - find.key = (hsize_t)(HDrandom() % INSERT_MANY_REC); + find.key = (hsize_t)(rand() % INSERT_MANY_REC); find.val = (hsize_t)-1; /* Attempt to find existent record in level-4 B-tree */ @@ -5112,7 +5112,7 @@ fprintf(stderr, "curr_time = %lu\n", (unsigned long)curr_time); hsize_t idx; /* Record index */ /* Pick random record */ - idx = (hsize_t)(HDrandom() % INSERT_MANY_REC); + idx = (hsize_t)(rand() % INSERT_MANY_REC); /* Reset find record */ find.key = (hsize_t)-1; @@ -8624,7 +8624,7 @@ test_remove_lots(const char *driver_name, hid_t fapl, const H5B2_create_t *cpara curr_time = 1163537969; fprintf(stderr, "curr_time = %lu\n", (unsigned long)curr_time); #endif - HDsrandom((unsigned)curr_time); + srand((unsigned)curr_time); /* * Test removing many records into v2 B-tree @@ -8643,7 +8643,7 @@ fprintf(stderr, "curr_time = %lu\n", (unsigned long)curr_time); hsize_t temp_rec; /* Temporary record */ unsigned swap_idx; /* Location to swap with when shuffling */ - swap_idx = ((unsigned)HDrandom() % (INSERT_MANY - u)) + u; + swap_idx = ((unsigned)rand() % (INSERT_MANY - u)) + u; temp_rec = records[u]; records[u] = records[swap_idx]; records[swap_idx] = temp_rec; @@ -8703,7 +8703,7 @@ fprintf(stderr, "curr_time = %lu\n", (unsigned long)curr_time); hsize_t temp_rec; /* Temporary record */ unsigned swap_idx; /* Location to swap with when shuffling */ - swap_idx = ((unsigned)HDrandom() % (INSERT_MANY - u)) + u; + swap_idx = ((unsigned)rand() % (INSERT_MANY - u)) + u; temp_rec = records[u]; records[u] = records[swap_idx]; records[swap_idx] = temp_rec; @@ -8797,7 +8797,7 @@ fprintf(stderr, "curr_time = %lu\n", (unsigned long)curr_time); /* Remove all records */ for (u = 0; u < INSERT_MANY; u++) { /* Pick a record index to remove from randomly */ - rem_idx = ((unsigned)HDrandom() % (INSERT_MANY - u)); + rem_idx = ((unsigned)rand() % (INSERT_MANY - u)); rrecord = HSIZET_MAX; /* Remove random record */ diff --git a/test/cache_api.c b/test/cache_api.c index de636cf4bb2..5ac6ca0a108 100644 --- a/test/cache_api.c +++ b/test/cache_api.c @@ -1184,9 +1184,9 @@ mdc_api_call_smoke_check(int express_test, unsigned paged, hid_t fcpl_id) /* do random reads on all datasets */ n = 0; while ((pass) && (n < NUM_RANDOM_ACCESSES)) { - m = HDrand() % NUM_DSETS; - i = (HDrand() % (DSET_SIZE / CHUNK_SIZE)) * CHUNK_SIZE; - j = (HDrand() % (DSET_SIZE / CHUNK_SIZE)) * CHUNK_SIZE; + m = rand() % NUM_DSETS; + i = (rand() % (DSET_SIZE / CHUNK_SIZE)) * CHUNK_SIZE; + j = (rand() % (DSET_SIZE / CHUNK_SIZE)) * CHUNK_SIZE; /* select on disk hyperslab */ offset[0] = (hsize_t)i; /*offset of hyperslab in file*/ @@ -1282,8 +1282,8 @@ mdc_api_call_smoke_check(int express_test, unsigned paged, hid_t fcpl_id) m = 0; n = 0; while ((pass) && (n < NUM_RANDOM_ACCESSES)) { - i = (HDrand() % (DSET_SIZE / CHUNK_SIZE)) * CHUNK_SIZE; - j = (HDrand() % (DSET_SIZE / CHUNK_SIZE)) * CHUNK_SIZE; + i = (rand() % (DSET_SIZE / CHUNK_SIZE)) * CHUNK_SIZE; + j = (rand() % (DSET_SIZE / CHUNK_SIZE)) * CHUNK_SIZE; /* select on disk hyperslab */ offset[0] = (hsize_t)i; /*offset of hyperslab in file*/ diff --git a/test/cmpd_dset.c b/test/cmpd_dset.c index 383ed7f1b5a..f19f0c4c87e 100644 --- a/test/cmpd_dset.c +++ b/test/cmpd_dset.c @@ -2831,7 +2831,7 @@ test_pack_ooo(void) * the compound */ unsigned i, j; /* Indices */ - HDsrand((unsigned)time(NULL)); + srand((unsigned)time(NULL)); /* Initialize "free_order" array to indicate that all slots in order are * free */ @@ -2842,7 +2842,7 @@ test_pack_ooo(void) for (i = 0; i < PACK_NMEMBS; i++) { /* Generate index into free_order array */ num_free = PACK_NMEMBS - i; - j = (unsigned)HDrandom() % num_free; + j = (unsigned)rand() % num_free; /* Update order array at the randomly generated (but guaranteed to be * free) location */ @@ -2854,7 +2854,7 @@ test_pack_ooo(void) } /* end for */ /* Generate order to insert inner compound type */ - sub_cmpd_order = (unsigned)HDrandom() % PACK_NMEMBS; + sub_cmpd_order = (unsigned)rand() % PACK_NMEMBS; for (extra_space = 0; extra_space < 2; extra_space++) { if (extra_space) diff --git a/test/dsets.c b/test/dsets.c index ca985a85ec6..90b15dc4134 100644 --- a/test/dsets.c +++ b/test/dsets.c @@ -2055,7 +2055,7 @@ test_filter_internal(hid_t fid, const char *name, hid_t dcpl, int if_fletcher32, for (i = 0; i < size[0]; i++) { for (j = 0; j < size[1] / 2; j++) { - points[i][j] = (int)HDrandom(); + points[i][j] = (int)rand(); } } if (H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, write_dxpl, points_data) < 0) @@ -2182,7 +2182,7 @@ test_filter_internal(hid_t fid, const char *name, hid_t dcpl, int if_fletcher32, for (i = 0; i < (size_t)hs_size[0]; i++) { for (j = 0; j < (size_t)hs_size[1]; j++) { - points[(size_t)hs_offset[0] + i][(size_t)hs_offset[1] + j] = (int)HDrandom(); + points[(size_t)hs_offset[0] + i][(size_t)hs_offset[1] + j] = (int)rand(); } } if (H5Sselect_hyperslab(sid, H5S_SELECT_SET, hs_offset, NULL, hs_size, NULL) < 0) @@ -3116,7 +3116,7 @@ test_onebyte_shuffle(hid_t file) for (i = 0; i < 10; i++) for (j = 0; j < 20; j++) - orig_data[i][j] = (unsigned char)HDrandom(); + orig_data[i][j] = (unsigned char)rand(); PASSED(); @@ -3232,7 +3232,7 @@ test_nbit_int(hid_t file) for (i = 0; i < (size_t)size[0]; i++) for (j = 0; j < (size_t)size[1]; j++) { power = pow(2.0, (double)(precision - 1)); - orig_data[i][j] = (int)(((long long)HDrandom() % (long long)power) << offset); + orig_data[i][j] = (int)(((long long)rand() % (long long)power) << offset); /* even-numbered values are negative */ if ((i * size[1] + j + 1) % 2 == 0) @@ -3608,9 +3608,8 @@ test_nbit_array(hid_t file) for (j = 0; j < (size_t)size[1]; j++) for (m = 0; m < (size_t)adims[0]; m++) for (n = 0; n < (size_t)adims[1]; n++) { - power = pow(2.0, (double)precision); - orig_data[i][j][m][n] = - (unsigned int)(((long long)HDrandom() % (long long)power) << offset); + power = pow(2.0, (double)precision); + orig_data[i][j][m][n] = (unsigned int)(((long long)rand() % (long long)power) << offset); } /* end for */ PASSED(); @@ -3802,11 +3801,11 @@ test_nbit_compound(hid_t file) for (i = 0; i < (size_t)size[0]; i++) for (j = 0; j < (size_t)size[1]; j++) { power = pow(2.0, (double)(precision[0] - 1)); - orig_data[i][j].i = (int)(((long long)HDrandom() % (long long)power) << offset[0]); + orig_data[i][j].i = (int)(((long long)rand() % (long long)power) << offset[0]); power = pow(2.0, (double)(precision[1] - 1)); - orig_data[i][j].c = (char)(((long long)HDrandom() % (long long)power) << offset[1]); + orig_data[i][j].c = (char)(((long long)rand() % (long long)power) << offset[1]); power = pow(2.0, (double)(precision[2] - 1)); - orig_data[i][j].s = (short)(((long long)HDrandom() % (long long)power) << offset[2]); + orig_data[i][j].s = (short)(((long long)rand() % (long long)power) << offset[2]); orig_data[i][j].f = float_val[i][j]; /* some even-numbered integer values are negative */ @@ -4081,33 +4080,30 @@ test_nbit_compound_2(hid_t file) for (i = 0; i < (size_t)size[0]; i++) for (j = 0; j < (size_t)size[1]; j++) { power = pow(2.0, (double)(precision[0] - 1)); - orig_data[i][j].a.i = (int)(((long long)HDrandom() % (long long)power) << offset[0]); + orig_data[i][j].a.i = (int)(((long long)rand() % (long long)power) << offset[0]); power = pow(2.0, (double)(precision[1] - 1)); - orig_data[i][j].a.c = (char)(((long long)HDrandom() % (long long)power) << offset[1]); + orig_data[i][j].a.c = (char)(((long long)rand() % (long long)power) << offset[1]); power = pow(2.0, (double)(precision[2] - 1)); - orig_data[i][j].a.s = (short)(-(((long long)HDrandom() % (long long)power) << offset[2])); + orig_data[i][j].a.s = (short)(-(((long long)rand() % (long long)power) << offset[2])); orig_data[i][j].a.f = float_val[i][j]; power = pow(2.0, (double)precision[3]); - orig_data[i][j].v = (unsigned int)(((long long)HDrandom() % (long long)power) << offset[3]); + orig_data[i][j].v = (unsigned int)(((long long)rand() % (long long)power) << offset[3]); for (m = 0; m < (size_t)array_dims[0]; m++) for (n = 0; n < (size_t)array_dims[1]; n++) { power = pow(2.0, (double)(precision[4] - 1)); - orig_data[i][j].b[m][n] = (char)(((long long)HDrandom() % (long long)power) << offset[4]); + orig_data[i][j].b[m][n] = (char)(((long long)rand() % (long long)power) << offset[4]); } /* end for */ for (m = 0; m < (size_t)array_dims[0]; m++) for (n = 0; n < (size_t)array_dims[1]; n++) { - power = pow(2.0, (double)(precision[0] - 1)); - orig_data[i][j].d[m][n].i = - (int)(-(((long long)HDrandom() % (long long)power) << offset[0])); - power = pow(2.0, (double)(precision[1] - 1)); - orig_data[i][j].d[m][n].c = - (char)(((long long)HDrandom() % (long long)power) << offset[1]); - power = pow(2.0, (double)(precision[2] - 1)); - orig_data[i][j].d[m][n].s = - (short)(((long long)HDrandom() % (long long)power) << offset[2]); + power = pow(2.0, (double)(precision[0] - 1)); + orig_data[i][j].d[m][n].i = (int)(-(((long long)rand() % (long long)power) << offset[0])); + power = pow(2.0, (double)(precision[1] - 1)); + orig_data[i][j].d[m][n].c = (char)(((long long)rand() % (long long)power) << offset[1]); + power = pow(2.0, (double)(precision[2] - 1)); + orig_data[i][j].d[m][n].s = (short)(((long long)rand() % (long long)power) << offset[2]); orig_data[i][j].d[m][n].f = float_val[i][j]; } /* end for */ } /* end for */ @@ -4335,7 +4331,7 @@ test_nbit_compound_3(hid_t file) for (i = 0; i < (size_t)size[0]; i++) { power = pow(2.0, 17.0 - 1.0); memset(&orig_data[i], 0, sizeof(orig_data[i])); - orig_data[i].i = (int)(HDrandom() % (long)power); + orig_data[i].i = (int)(rand() % (long)power); strcpy(orig_data[i].str, "fixed-length C string"); orig_data[i].vl_str = strdup("variable-length C string"); @@ -4520,7 +4516,7 @@ test_nbit_int_size(hid_t file) for (i = 0; i < DSET_DIM1; i++) for (j = 0; j < DSET_DIM2; j++) { power = pow(2.0, (double)(precision - 1)); - orig[i][j] = HDrandom() % (int)power << offset; + orig[i][j] = rand() % (int)power << offset; } /* Describe the dataspace. */ @@ -4728,7 +4724,7 @@ test_nbit_flt_size(hid_t file) */ for (i = 0; i < DSET_DIM1; i++) for (j = 0; j < DSET_DIM2; j++) - orig[i][j] = (float)(HDrandom() % 1234567) / 2; + orig[i][j] = (float)(rand() % 1234567) / 2; /* Describe the dataspace. */ dims[0] = DSET_DIM1; @@ -4878,7 +4874,7 @@ test_scaleoffset_int(hid_t file) /* Initialize data */ for (i = 0; i < (size_t)size[0]; i++) for (j = 0; j < (size_t)size[1]; j++) { - orig_data[i][j] = HDrandom() % 10000; + orig_data[i][j] = rand() % 10000; /* even-numbered values are negative */ if ((i * size[1] + j + 1) % 2 == 0) @@ -5019,7 +5015,7 @@ test_scaleoffset_int_2(hid_t file) /* Initialize data of hyperslab */ for (j = 0; j < (size_t)size[1]; j++) { - orig_data[0][j] = (int)HDrandom() % 10000; + orig_data[0][j] = (int)rand() % 10000; /* even-numbered values are negative */ if ((j + 1) % 2 == 0) @@ -5138,7 +5134,7 @@ test_scaleoffset_float(hid_t file) /* Initialize data */ for (i = 0; i < (size_t)size[0]; i++) for (j = 0; j < (size_t)size[1]; j++) { - orig_data[i][j] = (float)(HDrandom() % 100000) / 1000.0F; + orig_data[i][j] = (float)(rand() % 100000) / 1000.0F; /* even-numbered values are negative */ if ((i * size[1] + j + 1) % 2 == 0) @@ -5281,7 +5277,7 @@ test_scaleoffset_float_2(hid_t file) /* Initialize data of hyperslab */ for (j = 0; j < (size_t)size[1]; j++) { - orig_data[0][j] = (float)(HDrandom() % 100000) / 1000.0F; + orig_data[0][j] = (float)(rand() % 100000) / 1000.0F; /* even-numbered values are negative */ if ((j + 1) % 2 == 0) @@ -5399,7 +5395,7 @@ test_scaleoffset_double(hid_t file) /* Initialize data */ for (i = 0; i < (size_t)size[0]; i++) for (j = 0; j < (size_t)size[1]; j++) { - orig_data[i][j] = (HDrandom() % 10000000) / 10000000.0; + orig_data[i][j] = (rand() % 10000000) / 10000000.0; /* even-numbered values are negative */ if ((i * size[1] + j + 1) % 2 == 0) @@ -5542,7 +5538,7 @@ test_scaleoffset_double_2(hid_t file) /* Initialize data of hyperslab */ for (j = 0; j < (size_t)size[1]; j++) { - orig_data[0][j] = (HDrandom() % 10000000) / 10000000.0; + orig_data[0][j] = (rand() % 10000000) / 10000000.0; /* even-numbered values are negative */ if ((j + 1) % 2 == 0) @@ -8097,7 +8093,7 @@ make_random_offset_and_increment(long nelts, long *offsetp, long *incp) assert(0 < nelts); - *offsetp = HDrandom() % nelts; + *offsetp = rand() % nelts; /* `maxinc` is chosen so that for any `x` in [0, nelts - 1], * `x + maxinc` does not overflow a long. @@ -8110,7 +8106,7 @@ make_random_offset_and_increment(long nelts, long *offsetp, long *incp) * number. */ do { - inc = 1 + HDrandom() % maxinc; + inc = 1 + rand() % maxinc; } while (gcd(inc, nelts) != 1); *incp = inc; @@ -15921,7 +15917,7 @@ main(void) contig_addr_vfd = (bool)(strcmp(driver_name, "split") != 0 && strcmp(driver_name, "multi") != 0); /* Set the random # seed */ - HDsrandom((unsigned)time(NULL)); + srand((unsigned)time(NULL)); /* Initialize global arrays */ /* points */ diff --git a/test/dt_arith.c b/test/dt_arith.c index 62f03aaa4b4..34afdb92132 100644 --- a/test/dt_arith.c +++ b/test/dt_arith.c @@ -1039,7 +1039,7 @@ test_derived_flt(void) aligned = (int *)calloc((size_t)1, src_size); for (i = 0; i < nelmts * src_size; i++) - buf[i] = saved_buf[i] = (unsigned char)HDrand(); + buf[i] = saved_buf[i] = (unsigned char)rand(); /* Convert data from native integer to derived floating-point type. * The mantissa is big enough to retain the integer's precision. */ @@ -1199,7 +1199,7 @@ test_derived_flt(void) memset(saved_buf, 0, nelmts * src_size); for (i = 0; i < nelmts * src_size; i++) - buf[i] = saved_buf[i] = (unsigned char)HDrand(); + buf[i] = saved_buf[i] = (unsigned char)rand(); /* Convert data from the 2nd to the 1st derived floating-point type. * The mantissa and exponent of the 2nd type are big enough to retain @@ -1520,7 +1520,7 @@ test_derived_integer(void) memset(saved_buf, 0, nelmts * src_size); for (i = 0; i < nelmts * src_size; i++) - buf[i] = saved_buf[i] = (unsigned char)HDrand(); + buf[i] = saved_buf[i] = (unsigned char)rand(); /* Convert data from the 1st to the 2nd derived integer type. * The precision of the 2nd type are big enough to retain @@ -5978,7 +5978,7 @@ main(void) unsigned long nerrors = 0; /* Set the random # seed */ - HDsrandom((unsigned)time(NULL)); + srand((unsigned)time(NULL)); reset_hdf5(); diff --git a/test/dtypes.c b/test/dtypes.c index 51dbf123fe0..cebc1b525b5 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -5154,9 +5154,9 @@ test_conv_str_2(void) if (NULL == (buf = (char *)calloc(nelmts, (size_t)8))) goto error; for (i = 0; i < nelmts; i++) { - nchars = (size_t)(HDrand() % 8); + nchars = (size_t)(rand() % 8); for (j = 0; j < nchars; j++) - buf[i * 8 + j] = (char)('a' + HDrand() % 26); + buf[i * 8 + j] = (char)('a' + rand() % 26); while (j < nchars) buf[i * 8 + j++] = '\0'; } /* end for */ @@ -5228,9 +5228,9 @@ test_conv_str_3(void) if (NULL == (buf = (char *)calloc(nelmts, (size_t)8))) FAIL_PUTS_ERROR("Allocation failed."); for (i = 0; i < nelmts; i++) { - nchars = (size_t)(HDrand() % 8); + nchars = (size_t)(rand() % 8); for (j = 0; j < nchars; j++) - buf[i * 8 + j] = (char)('a' + HDrand() % 26); + buf[i * 8 + j] = (char)('a' + rand() % 26); while (j < nchars) buf[i * 8 + j++] = '\0'; } /* end for */ @@ -5367,7 +5367,7 @@ test_conv_enum_1(void) if (NULL == (buf = (int *)malloc(nelmts * MAX(H5Tget_size(t1), H5Tget_size(t2))))) goto error; for (u = 0; u < nelmts; u++) - buf[u] = HDrand() % 26; + buf[u] = rand() % 26; /* Conversions */ snprintf(s, sizeof(s), "Testing random enum conversion O(N)"); @@ -10129,7 +10129,7 @@ main(void) hid_t fapl = H5I_INVALID_HID; /* Set the random # seed */ - HDsrandom((unsigned)time(NULL)); + srand((unsigned)time(NULL)); reset_hdf5(); fapl = h5_fileaccess(); diff --git a/test/earray.c b/test/earray.c index 3770ac44765..1402e33d4e1 100644 --- a/test/earray.c +++ b/test/earray.c @@ -1650,7 +1650,7 @@ eiter_rnd_init(const H5EA_create_t H5_ATTR_UNUSED *cparam, const earray_test_par size_t swap_idx; /* Location to swap with when shuffling */ hsize_t temp_idx; /* Temporary index */ - swap_idx = ((size_t)HDrandom() % ((size_t)cnt - u)) + u; + swap_idx = ((size_t)rand() % ((size_t)cnt - u)) + u; temp_idx = eiter->idx[u]; eiter->idx[u] = eiter->idx[swap_idx]; eiter->idx[swap_idx] = temp_idx; @@ -1796,7 +1796,7 @@ eiter_rnd2_init(const H5EA_create_t H5_ATTR_UNUSED *cparam, const earray_test_pa for (u = 0; u < (size_t)cnt; u++) { size_t swap_idx; /* Location to swap with when shuffling */ - swap_idx = ((size_t)HDrandom() % ((size_t)sparse_cnt - u)) + u; + swap_idx = ((size_t)rand() % ((size_t)sparse_cnt - u)) + u; eiter->idx[u] = tmp_idx[swap_idx]; tmp_idx[swap_idx] = tmp_idx[u]; } /* end for */ @@ -2297,7 +2297,6 @@ main(void) earray_iter_type_t curr_iter; /* Current iteration type being worked on */ hid_t fapl = H5I_INVALID_HID; /* File access property list for data files */ unsigned nerrors = 0; /* Cumulative error count */ - time_t curr_time; /* Current time, for seeding random number generator */ int ExpressMode; /* Test express value */ bool api_ctx_pushed = false; /* Whether API context pushed */ @@ -2317,8 +2316,7 @@ main(void) api_ctx_pushed = true; /* Seed random #'s */ - curr_time = time(NULL); - HDsrandom((unsigned)curr_time); + srand((unsigned)time(NULL)); /* Create an empty file to retrieve size */ { diff --git a/test/farray.c b/test/farray.c index a8f4352c984..12166228d1d 100644 --- a/test/farray.c +++ b/test/farray.c @@ -1149,7 +1149,7 @@ fiter_rnd_init(const H5FA_create_t H5_ATTR_UNUSED *cparam, const farray_test_par size_t swap_idx; /* Location to swap with when shuffling */ hsize_t temp_idx; /* Temporary index */ - swap_idx = ((size_t)HDrandom() % ((size_t)cnt - u)) + u; + swap_idx = ((size_t)rand() % ((size_t)cnt - u)) + u; temp_idx = fiter->idx[u]; fiter->idx[u] = fiter->idx[swap_idx]; fiter->idx[swap_idx] = temp_idx; @@ -1628,7 +1628,6 @@ main(void) farray_iter_type_t curr_iter; /* Current iteration type being worked on */ hid_t fapl = H5I_INVALID_HID; /* File access property list for data files */ unsigned nerrors = 0; /* Cumulative error count */ - time_t curr_time; /* Current time, for seeding random number generator */ int ExpressMode; /* Test express value */ bool api_ctx_pushed = false; /* Whether API context pushed */ @@ -1648,8 +1647,7 @@ main(void) api_ctx_pushed = true; /* Seed random #'s */ - curr_time = time(NULL); - HDsrandom((unsigned)curr_time); + srand((unsigned)time(NULL)); /* Create an empty file to retrieve size */ { diff --git a/test/fheap.c b/test/fheap.c index 0784aa775e9..5f212858456 100644 --- a/test/fheap.c +++ b/test/fheap.c @@ -6239,12 +6239,12 @@ test_man_remove_bogus(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tpa /* seed = (unsigned long)1155438845; */ fprintf(stderr, "Random # seed was: %lu\n", seed); #endif - HDsrandom((unsigned)seed); + srand((unsigned)seed); /* Set heap ID to random (non-null) value */ heap_id[0] = H5HF_ID_VERS_CURR | H5HF_ID_TYPE_MAN; for (u = 1; u < HEAP_ID_LEN; u++) - heap_id[u] = (unsigned char)(HDrandom() + 1); + heap_id[u] = (unsigned char)(rand() + 1); /* Try removing bogus heap ID from empty heap */ H5E_BEGIN_TRY @@ -6268,7 +6268,7 @@ fprintf(stderr, "Random # seed was: %lu\n", seed); /* Set heap ID to random (non-null) value */ heap_id[0] = H5HF_ID_VERS_CURR | H5HF_ID_TYPE_MAN; for (u = 1; u < HEAP_ID_LEN; u++) - heap_id[u] = (unsigned char)(HDrandom() + 1); + heap_id[u] = (unsigned char)(rand() + 1); /* Get offset of random heap ID */ if (H5HF_get_id_off_test(fh, heap_id, &obj_off) < 0) @@ -15147,13 +15147,13 @@ test_random(hsize_t size_limit, hid_t fapl, H5HF_create_t *cparam, fheap_test_pa /* seed = (unsigned long)1156158635; */ fprintf(stderr, "Random # seed was: %lu\n", seed); #endif - HDsrandom((unsigned)seed); + srand((unsigned)seed); /* Loop over adding objects to the heap, until the size limit is reached */ total_obj_added = 0; while (total_obj_added < size_limit) { /* Choose a random size of object (from 1 up to above standalone block size limit) */ - obj_size = (((uint32_t)HDrandom() % (tmp_cparam.max_man_size + 255)) + 1); + obj_size = (((uint32_t)rand() % (tmp_cparam.max_man_size + 255)) + 1); obj_loc = (tmp_cparam.max_man_size + 255) - obj_size; /* Insert object */ @@ -15174,7 +15174,7 @@ fprintf(stderr, "Random # seed was: %lu\n", seed); /* Choose a position to swap with */ /* (0 is current position) */ - pos = ((size_t)HDrandom() % (keep_ids.num_ids - u)); + pos = ((size_t)rand() % (keep_ids.num_ids - u)); /* If we chose a different position, swap with it */ if (pos > 0) { @@ -15350,7 +15350,7 @@ test_random_pow2(hsize_t size_limit, hid_t fapl, H5HF_create_t *cparam, fheap_te /* seed = (unsigned long)1155181717; */ fprintf(stderr, "Random # seed was: %lu\n", seed); #endif - HDsrandom((unsigned)seed); + srand((unsigned)seed); /* Loop over adding objects to the heap, until the size limit is reached */ total_obj_added = 0; @@ -15362,13 +15362,13 @@ fprintf(stderr, "Random # seed was: %lu\n", seed); * 25% of the objects will be twice as large, 12.5% will be * four times larger, etc.) */ - while (HDrandom() < (RAND_MAX / 2) && size_range < tmp_cparam.max_man_size) + while (rand() < (RAND_MAX / 2) && size_range < tmp_cparam.max_man_size) size_range *= 2; if (size_range > (tmp_cparam.max_man_size + 255)) size_range = tmp_cparam.max_man_size + 255; /* Choose a random size of object (from 1 up to stand alone block size) */ - obj_size = (((unsigned)HDrandom() % (size_range - 1)) + 1); + obj_size = (((unsigned)rand() % (size_range - 1)) + 1); obj_loc = (tmp_cparam.max_man_size + 255) - obj_size; /* Insert object */ @@ -15389,7 +15389,7 @@ fprintf(stderr, "Random # seed was: %lu\n", seed); /* Choose a position to swap with */ /* (0 is current position) */ - pos = ((size_t)HDrandom() % (keep_ids.num_ids - u)); + pos = ((size_t)rand() % (keep_ids.num_ids - u)); /* If we chose a different position, swap with it */ if (pos > 0) { diff --git a/test/fillval.c b/test/fillval.c index c8f46387b74..64a33e04ff8 100644 --- a/test/fillval.c +++ b/test/fillval.c @@ -920,7 +920,7 @@ test_rdwr_cases(hid_t file, hid_t dcpl, const char *dname, void *_fillval, H5D_f goto error; for (i = 0; i < 1000; i++) { for (j = 0; j < 5; j++) - hs_offset[j] = (hsize_t)HDrand() % cur_size[j]; + hs_offset[j] = (hsize_t)rand() % cur_size[j]; if (H5Sselect_hyperslab(fspace, H5S_SELECT_SET, hs_offset, NULL, one, NULL) < 0) goto error; @@ -1073,7 +1073,7 @@ test_rdwr_cases(hid_t file, hid_t dcpl, const char *dname, void *_fillval, H5D_f goto error; for (i = 0; i < 1000; i++) { for (j = 0, odd = 0; j < 5; j++) { - hs_offset[j] = (hsize_t)HDrand() % cur_size[j]; + hs_offset[j] = (hsize_t)rand() % cur_size[j]; odd += (int)(hs_offset[j] % 2); } /* end for */ if (H5Sselect_hyperslab(fspace, H5S_SELECT_SET, hs_offset, NULL, one, NULL) < 0) @@ -1644,7 +1644,7 @@ test_extend_cases(hid_t file, hid_t _dcpl, const char *dset_name, const hsize_t for (i = 0; i < 1000; i++) { /* Set offset for random element */ for (j = 0; j < 5; j++) - hs_offset[j] = (hsize_t)HDrand() % start_size[j]; + hs_offset[j] = (hsize_t)rand() % start_size[j]; /* Select the random element */ if (H5Sselect_hyperslab(fspace, H5S_SELECT_SET, hs_offset, NULL, one, NULL) < 0) @@ -1705,7 +1705,7 @@ test_extend_cases(hid_t file, hid_t _dcpl, const char *dset_name, const hsize_t for (i = 0; i < 1000; i++) { /* Set offset for random element */ for (j = 0, odd = 0; j < 5; j++) { - hs_offset[j] = (hsize_t)HDrand() % start_size[j]; + hs_offset[j] = (hsize_t)rand() % start_size[j]; odd += (unsigned)(hs_offset[j] % 2); } /* end for */ @@ -1750,7 +1750,7 @@ test_extend_cases(hid_t file, hid_t _dcpl, const char *dset_name, const hsize_t for (i = 0; i < 1000; i++) { /* Set offset for random element */ for (j = 0, odd = 0; j < 5; j++) { - hs_offset[j] = (hsize_t)HDrand() % extend_size[j]; + hs_offset[j] = (hsize_t)rand() % extend_size[j]; if (hs_offset[j] >= start_size[j]) odd = 1; else @@ -1796,7 +1796,7 @@ test_extend_cases(hid_t file, hid_t _dcpl, const char *dset_name, const hsize_t for (i = 0; i < 1000; i++) { /* Set offset for random element */ for (j = 0, odd = 0; j < 5; j++) { - hs_offset[j] = (hsize_t)HDrand() % max_size[j]; + hs_offset[j] = (hsize_t)rand() % max_size[j]; if (hs_offset[j] >= start_size[j]) odd = 1; else @@ -1844,7 +1844,7 @@ test_extend_cases(hid_t file, hid_t _dcpl, const char *dset_name, const hsize_t for (i = 0; i < 1000; i++) { /* Set offset for random element */ for (j = 0, odd = 0; j < 5; j++) { - hs_offset[j] = (hsize_t)HDrand() % extend_size[j]; + hs_offset[j] = (hsize_t)rand() % extend_size[j]; if (hs_offset[j] >= start_size[j]) odd = 1; else @@ -1952,7 +1952,7 @@ test_extend_cases(hid_t file, hid_t _dcpl, const char *dset_name, const hsize_t for (i = 0; i < 1000; i++) { /* Set offset for random element */ for (j = 0, odd = 0; j < 5; j++) { - hs_offset[j] = (hsize_t)HDrand() % extend_size[j]; + hs_offset[j] = (hsize_t)rand() % extend_size[j]; if (hs_offset[j] >= start_size[j]) odd = 1; else diff --git a/test/filter_plugin.c b/test/filter_plugin.c index 9207d9e847c..4e4f86b41e3 100644 --- a/test/filter_plugin.c +++ b/test/filter_plugin.c @@ -294,7 +294,7 @@ ensure_filter_works(hid_t fid, const char *name, hid_t dcpl_id) for (i = 0; i < r; i++) for (j = 0; j < c / 2; j++) - orig[i][j] = (int)HDrandom() % RANDOM_LIMIT; + orig[i][j] = (int)rand() % RANDOM_LIMIT; if (H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, write_dxpl_id, *orig) < 0) TEST_ERROR; @@ -349,7 +349,7 @@ ensure_filter_works(hid_t fid, const char *name, hid_t dcpl_id) hs_offc = (size_t)hs_offsets_g[1]; for (i = 0; i < hs_r; i++) for (j = 0; j < hs_c; j++) - orig[hs_offr + i][hs_offc + j] = (int)HDrandom() % RANDOM_LIMIT; + orig[hs_offr + i][hs_offc + j] = (int)rand() % RANDOM_LIMIT; if (H5Sselect_hyperslab(sid, H5S_SELECT_SET, hs_offsets_g, NULL, hs_sizes_g, NULL) < 0) TEST_ERROR; diff --git a/test/hyperslab.c b/test/hyperslab.c index da014d30355..16298331122 100644 --- a/test/hyperslab.c +++ b/test/hyperslab.c @@ -1063,9 +1063,9 @@ test_array_offset_n_calc(size_t n, size_t x, size_t y, size_t z) /* Check offsets */ for (u = 0; u < n; u++) { /* Get random coordinate */ - coords[0] = (hsize_t)((size_t)HDrandom() % z); - coords[1] = (hsize_t)((size_t)HDrandom() % y); - coords[2] = (hsize_t)((size_t)HDrandom() % x); + coords[0] = (hsize_t)((size_t)rand() % z); + coords[1] = (hsize_t)((size_t)rand() % y); + coords[2] = (hsize_t)((size_t)rand() % x); /* Get offset of coordinate */ off = H5VM_array_offset(ARRAY_OFFSET_NDIMS, dims, coords); @@ -1144,7 +1144,7 @@ main(int argc, char *argv[]) printf("\n"); /* Set the random # seed */ - HDsrandom((unsigned)time(NULL)); + srand((unsigned)time(NULL)); /* * Open the library explicitly for thread-safe builds, so per-thread diff --git a/test/istore.c b/test/istore.c index 5a1fa0ff498..1934cc37b0b 100644 --- a/test/istore.c +++ b/test/istore.c @@ -480,9 +480,9 @@ test_sparse(hid_t f, const char *prefix, size_t nblocks, size_t nx, size_t ny, s TEST_ERROR; for (ctr = 0; ctr < nblocks; ctr++) { - offset[0] = (hsize_t)(HDrandom() % (int)(TEST_SPARSE_SIZE - nx)); - offset[1] = (hsize_t)(HDrandom() % (int)(TEST_SPARSE_SIZE - ny)); - offset[2] = (hsize_t)(HDrandom() % (int)(TEST_SPARSE_SIZE - nz)); + offset[0] = (hsize_t)(rand() % (int)(TEST_SPARSE_SIZE - nx)); + offset[1] = (hsize_t)(rand() % (int)(TEST_SPARSE_SIZE - ny)); + offset[2] = (hsize_t)(rand() % (int)(TEST_SPARSE_SIZE - nz)); /* Select region in file dataspace */ if (H5Sselect_hyperslab(fspace, H5S_SELECT_SET, offset, NULL, size, NULL) < 0) @@ -582,7 +582,7 @@ main(int argc, char *argv[]) printf("\n"); /* Set the random # seed */ - HDsrandom((unsigned)time(NULL)); + srand((unsigned)time(NULL)); /* Check to see if the file system supports POSIX-style sparse files. * Windows NTFS does not, so we want to avoid tests which create diff --git a/test/mdset.c b/test/mdset.c index 145618b60ea..0091bc26e79 100644 --- a/test/mdset.c +++ b/test/mdset.c @@ -310,7 +310,7 @@ test_mdset(size_t niter, unsigned flags, hid_t fapl_id) for (i = 0; i < niter; i++) { /* Determine number of datasets */ ndsets = (flags & MDSET_FLAG_MLAYOUT) ? 6 - : (flags & MDSET_FLAG_MDSET) ? (size_t)((size_t)HDrandom() % max_dsets) + 1 + : (flags & MDSET_FLAG_MDSET) ? (size_t)((size_t)rand() % max_dsets) + 1 : 1; /* Create file */ @@ -325,16 +325,16 @@ test_mdset(size_t niter, unsigned flags, hid_t fapl_id) (flags & MDSET_FLAG_CHUNK) || ((flags & MDSET_FLAG_MLAYOUT) && (j == 1 || j == 2)); /* Generate file dataspace */ - dset_dims[j][0] = (hsize_t)((HDrandom() % MAX_DSET_X) + 1); - dset_dims[j][1] = (hsize_t)((HDrandom() % MAX_DSET_Y) + 1); + dset_dims[j][0] = (hsize_t)((rand() % MAX_DSET_X) + 1); + dset_dims[j][1] = (hsize_t)((rand() % MAX_DSET_Y) + 1); if ((file_space_ids[j] = H5Screate_simple(2, dset_dims[j], use_chunk ? max_dims : NULL)) < 0) TEST_ERROR; /* Generate chunk if called for by configuration (multi layout uses chunked for datasets * 1 and 2) */ if (use_chunk) { - chunk_dims[0] = (hsize_t)((HDrandom() % MAX_CHUNK_X) + 1); - chunk_dims[1] = (hsize_t)((HDrandom() % MAX_CHUNK_Y) + 1); + chunk_dims[0] = (hsize_t)((rand() % MAX_CHUNK_X) + 1); + chunk_dims[1] = (hsize_t)((rand() % MAX_CHUNK_Y) + 1); if (H5Pset_chunk(dcpl_id[j], 2, chunk_dims) < 0) TEST_ERROR; } /* end if */ @@ -352,18 +352,18 @@ test_mdset(size_t niter, unsigned flags, hid_t fapl_id) /* Create dataset */ /* If MDSET_FLAG_TCONV is set, use a different datatype with 50% probability, so * some datasets require type conversion and others do not */ - if ((dset_ids[j] = H5Dcreate2(file_id, dset_name[j], - (flags & MDSET_FLAG_TCONV && HDrandom() % 2) ? H5T_NATIVE_LONG - : H5T_NATIVE_UINT, - file_space_ids[j], H5P_DEFAULT, dcpl_id[j], H5P_DEFAULT)) < 0) + if ((dset_ids[j] = + H5Dcreate2(file_id, dset_name[j], + (flags & MDSET_FLAG_TCONV && rand() % 2) ? H5T_NATIVE_LONG : H5T_NATIVE_UINT, + file_space_ids[j], H5P_DEFAULT, dcpl_id[j], H5P_DEFAULT)) < 0) TEST_ERROR; /* Create virtual source dataset if necessary. Use dcpl_id[0] for a contiguous dataset */ if ((flags & MDSET_FLAG_MLAYOUT) && (j == 6)) { if ((source_dset = H5Dcreate2(file_id, SOURCE_DS_NAME, - (flags & MDSET_FLAG_TCONV && HDrandom() % 2) ? H5T_NATIVE_LONG - : H5T_NATIVE_UINT, + (flags & MDSET_FLAG_TCONV && rand() % 2) ? H5T_NATIVE_LONG + : H5T_NATIVE_UINT, file_space_ids[j], H5P_DEFAULT, dcpl_id[0], H5P_DEFAULT)) < 0) TEST_ERROR; if (H5Dclose(source_dset) < 0) @@ -388,7 +388,7 @@ test_mdset(size_t niter, unsigned flags, hid_t fapl_id) for (j = 0; j < OPS_PER_FILE; j++) { /* Decide whether to read or write. Can't read on the first iteration with external * layout because the write is needed to create the external file. */ - do_read = (j == 0 && flags & MDSET_FLAG_MLAYOUT) ? false : (bool)(HDrandom() % 2); + do_read = (j == 0 && flags & MDSET_FLAG_MLAYOUT) ? false : (bool)(rand() % 2); /* Loop over datasets */ for (k = 0; k < ndsets; k++) { @@ -401,10 +401,10 @@ test_mdset(size_t niter, unsigned flags, hid_t fapl_id) TEST_ERROR; /* Decide whether to do a hyperslab, point, or all selection */ - sel_type = HDrandom() % 3; + sel_type = rand() % 3; if (sel_type == 0) { /* Hyperslab */ - size_t nhs = (size_t)((HDrandom() % MAX_HS) + 1); /* Number of hyperslabs */ + size_t nhs = (size_t)((rand() % MAX_HS) + 1); /* Number of hyperslabs */ size_t max_hs_x = (MAX_HS_X <= dset_dims[k][0]) ? MAX_HS_X : dset_dims[k][0]; /* Determine maximum hyperslab size in X */ @@ -414,14 +414,14 @@ test_mdset(size_t niter, unsigned flags, hid_t fapl_id) for (l = 0; l < nhs; l++) { /* Generate hyperslab */ - count[0] = (hsize_t)(((hsize_t)HDrandom() % max_hs_x) + 1); - count[1] = (hsize_t)(((hsize_t)HDrandom() % max_hs_y) + 1); + count[0] = (hsize_t)(((hsize_t)rand() % max_hs_x) + 1); + count[1] = (hsize_t)(((hsize_t)rand() % max_hs_y) + 1); start[0] = (count[0] == dset_dims[k][0]) ? 0 - : (hsize_t)HDrandom() % (dset_dims[k][0] - count[0] + 1); + : (hsize_t)rand() % (dset_dims[k][0] - count[0] + 1); start[1] = (count[1] == dset_dims[k][1]) ? 0 - : (hsize_t)HDrandom() % (dset_dims[k][1] - count[1] + 1); + : (hsize_t)rand() % (dset_dims[k][1] - count[1] + 1); /* Select hyperslab */ if (H5Sselect_hyperslab(mem_space_ids[k], H5S_SELECT_OR, start, NULL, count, NULL) < @@ -445,12 +445,12 @@ test_mdset(size_t niter, unsigned flags, hid_t fapl_id) } /* end if */ else if (sel_type == 1) { /* Point selection */ - size_t npoints = (size_t)(((size_t)HDrandom() % MAX_POINTS) + 1); /* Number of points */ + size_t npoints = (size_t)(((size_t)rand() % MAX_POINTS) + 1); /* Number of points */ /* Generate points */ for (l = 0; l < npoints; l++) { - points[2 * l] = (unsigned)((hsize_t)HDrandom() % dset_dims[k][0]); - points[(2 * l) + 1] = (unsigned)((hsize_t)HDrandom() % dset_dims[k][1]); + points[2 * l] = (unsigned)((hsize_t)rand() % dset_dims[k][0]); + points[(2 * l) + 1] = (unsigned)((hsize_t)rand() % dset_dims[k][1]); } /* end for */ /* Select points in file */ @@ -646,7 +646,7 @@ main(void) fapl_id = h5_fileaccess(); /* Initialize random number seed */ - HDsrandom((unsigned)time(NULL)); + srand((unsigned)time(NULL)); /* Fill dset_name array */ for (i = 0; i < MAX_DSETS; i++) { diff --git a/test/ntypes.c b/test/ntypes.c index 5d6b37164b8..3b5bd662bcc 100644 --- a/test/ntypes.c +++ b/test/ntypes.c @@ -3080,7 +3080,7 @@ test__Float16(hid_t file) /* Initialize the data */ for (size_t i = 0; i < DIM0; i++) for (size_t j = 0; j < DIM1; j++) - ipoints->arr[i][j] = (H5__Float16)(HDrand() / (double)RAND_MAX); + ipoints->arr[i][j] = (H5__Float16)(rand() / (double)RAND_MAX); /* Create the data space */ dims[0] = DIM0; diff --git a/test/select_io_dset.c b/test/select_io_dset.c index 2f440d8eec0..3daa63f2d38 100644 --- a/test/select_io_dset.c +++ b/test/select_io_dset.c @@ -1165,9 +1165,8 @@ test_multi_dsets_no_bkg(hid_t fid, unsigned set_cache, unsigned chunked, unsigne chunked ? "chunked" : "contig", dtrans ? "xform" : "noxform", mwbuf ? "mwbuf" : "nomwbuf"); /* Create ith dataset */ - if ((dset_dids[i] = - H5Dcreate2(fid, dset_names[i], ((HDrandom() % 2) ? H5T_NATIVE_LONG : H5T_NATIVE_INT), - file_sids[i], H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) + if ((dset_dids[i] = H5Dcreate2(fid, dset_names[i], ((rand() % 2) ? H5T_NATIVE_LONG : H5T_NATIVE_INT), + file_sids[i], H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) TEST_ERROR; } @@ -1651,7 +1650,7 @@ test_multi_dsets_cmpd_with_bkg(hid_t fid, unsigned chunked, unsigned mwbuf) } /* Case c */ - mm = HDrandom() % (int)ndsets; + mm = rand() % (int)ndsets; if (!mm) mm++; @@ -2401,7 +2400,7 @@ test_multi_dsets_all(int niter, hid_t fid, unsigned chunked, unsigned mwbuf) if ((mem_sids[i] = H5Screate_simple(1, dims, NULL)) < 0) TEST_ERROR; - mm = HDrandom() % (int)ndsets; + mm = rand() % (int)ndsets; if (mm == 0) { dset_types[i] = DSET_WITH_NO_CONV; snprintf(dset_names[i], sizeof(dset_names[i]), "multi_all_nconv_dset%d_%s_%s", i, diff --git a/test/set_extent.c b/test/set_extent.c index 1db56bab6b9..696ef96f36d 100644 --- a/test/set_extent.c +++ b/test/set_extent.c @@ -119,7 +119,7 @@ main(void) contig_addr_vfd = (bool)(strcmp(driver_name, "split") != 0 && strcmp(driver_name, "multi") != 0); /* Initialize random number seed */ - HDsrandom((unsigned)time(NULL)); + srand((unsigned)time(NULL)); h5_reset(); fapl = h5_fileaccess(); @@ -2345,17 +2345,16 @@ test_random_rank4(hid_t fapl, hid_t dcpl, hid_t dxpl, bool do_fillvalue, bool di /* Generate random chunk dimensions, 2-4 */ for (i = 0; i < 4; i++) - cdims[i] = (hsize_t)((HDrandom() % 3) + 2); + cdims[i] = (hsize_t)((rand() % 3) + 2); /* Pick iteration to shrink dataset to 1x1x1x1 */ - scalar_iter = (unsigned)(HDrandom() % RAND4_NITER); + scalar_iter = (unsigned)(rand() % RAND4_NITER); /* Generate initial dataset size, 1-10, unless using fixed array index or * scalar_iter is 0 */ for (i = 0; i < 4; i++) { dims[i] = - (hsize_t)(index_type != RANK4_INDEX_FARRAY ? (0 == scalar_iter ? 1 : ((HDrandom() % 10) + 1)) - : 10); + (hsize_t)(index_type != RANK4_INDEX_FARRAY ? (0 == scalar_iter ? 1 : ((rand() % 10) + 1)) : 10); dim_log->arr[0][i] = dims[i]; } /* end for */ @@ -2389,7 +2388,7 @@ test_random_rank4(hid_t fapl, hid_t dcpl, hid_t dxpl, bool do_fillvalue, bool di for (k = 0; k < dims[1]; k++) for (l = 0; l < dims[2]; l++) for (m = 0; m < dims[3]; m++) - wbuf->arr[j][k][l][m] = HDrandom(); + wbuf->arr[j][k][l][m] = rand(); /* Write data */ if (H5Dwrite(dset, H5T_NATIVE_INT, mspace, H5S_ALL, dxpl, wbuf) < 0) @@ -2401,8 +2400,8 @@ test_random_rank4(hid_t fapl, hid_t dcpl, hid_t dxpl, bool do_fillvalue, bool di zero_dim = false; for (j = 0; j < 4; j++) { old_dims[j] = dims[j]; - if ((dims[j] = (hsize_t)(i == scalar_iter ? 1 : (HDrandom() % 11))) == 0) - if ((dims[j] = (hsize_t)(HDrandom() % 11)) == 0) + if ((dims[j] = (hsize_t)(i == scalar_iter ? 1 : (rand() % 11))) == 0) + if ((dims[j] = (hsize_t)(rand() % 11)) == 0) zero_dim = true; dim_log->arr[i + 1][j] = dims[j]; } /* end for */ @@ -2592,17 +2591,16 @@ test_random_rank4_vl(hid_t fapl, hid_t dcpl, hid_t dxpl, bool do_fillvalue, bool /* Generate random chunk dimensions, 2-4 */ for (i = 0; i < 4; i++) - cdims[i] = (hsize_t)((HDrandom() % 3) + 2); + cdims[i] = (hsize_t)((rand() % 3) + 2); /* Pick iteration to shrink dataset to 1x1x1x1 */ - scalar_iter = (unsigned)(HDrandom() % RAND4_NITER); + scalar_iter = (unsigned)(rand() % RAND4_NITER); /* Generate initial dataset size, 1-10, unless using fixed array index or * scalar_iter is 0 */ for (i = 0; i < 4; i++) { dims[i] = - (hsize_t)(index_type != RANK4_INDEX_FARRAY ? (0 == scalar_iter ? 1 : ((HDrandom() % 10) + 1)) - : 10); + (hsize_t)(index_type != RANK4_INDEX_FARRAY ? (0 == scalar_iter ? 1 : ((rand() % 10) + 1)) : 10); dim_log->arr[0][i] = dims[i]; } @@ -2649,8 +2647,8 @@ test_random_rank4_vl(hid_t fapl, hid_t dcpl, hid_t dxpl, bool do_fillvalue, bool for (k = 0; k < dims[1]; k++) for (l = 0; l < dims[2]; l++) for (m = 0; m < dims[3]; m++) { - ((int *)wbuf->arr[j][k][l][m].p)[0] = HDrandom(); - ((int *)wbuf->arr[j][k][l][m].p)[1] = HDrandom(); + ((int *)wbuf->arr[j][k][l][m].p)[0] = rand(); + ((int *)wbuf->arr[j][k][l][m].p)[1] = rand(); } /* end for */ /* Write data */ @@ -2663,8 +2661,8 @@ test_random_rank4_vl(hid_t fapl, hid_t dcpl, hid_t dxpl, bool do_fillvalue, bool zero_dim = false; for (j = 0; j < 4; j++) { old_dims[j] = dims[j]; - if ((dims[j] = (hsize_t)(i == scalar_iter ? 1 : (HDrandom() % 11))) == 0) - if ((dims[j] = (hsize_t)(HDrandom() % 11)) == 0) + if ((dims[j] = (hsize_t)(i == scalar_iter ? 1 : (rand() % 11))) == 0) + if ((dims[j] = (hsize_t)(rand() % 11)) == 0) zero_dim = true; dim_log->arr[i + 1][j] = dims[j]; } diff --git a/test/stab.c b/test/stab.c index 357f7682712..3f4a8360bec 100644 --- a/test/stab.c +++ b/test/stab.c @@ -296,7 +296,7 @@ test_large(hid_t fcpl, hid_t fapl, bool new_format) if (H5G__has_stab_test(cwg) != false) TEST_ERROR; for (i = 0; i < LARGE_NOBJS; i++) { - snprintf(name, sizeof(name), "%05d%05d", (HDrandom() % 100000), i); + snprintf(name, sizeof(name), "%05d%05d", (rand() % 100000), i); if ((dir = H5Gcreate2(cwg, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; if (H5Gclose(dir) < 0) diff --git a/test/swmr_addrem_writer.c b/test/swmr_addrem_writer.c index 8fd907af5db..8e42f2436fc 100644 --- a/test/swmr_addrem_writer.c +++ b/test/swmr_addrem_writer.c @@ -172,7 +172,7 @@ addrem_records(hid_t fid, unsigned verbose, unsigned long nops, unsigned long fl symbol = choose_dataset(); /* Decide whether to shrink or expand, and by how much */ - count[1] = (hsize_t)HDrandom() % (MAX_SIZE_CHANGE * 2) + 1; + count[1] = (hsize_t)rand() % (MAX_SIZE_CHANGE * 2) + 1; if (count[1] > MAX_SIZE_CHANGE) { /* Add records */ @@ -359,7 +359,7 @@ main(int argc, char *argv[]) HDgettimeofday(&t, NULL); random_seed = (unsigned)(t.tv_usec); } /* end if */ - HDsrandom(random_seed); + srand(random_seed); /* ALWAYS emit the random seed for possible debugging */ fprintf(stderr, "Using writer random seed: %u\n", random_seed); diff --git a/test/swmr_common.c b/test/swmr_common.c index dd7dd8edd18..b95bdf67b56 100644 --- a/test/swmr_common.c +++ b/test/swmr_common.c @@ -102,10 +102,10 @@ choose_dataset(void) unsigned offset; /* The "offset" of the dataset at that level */ /* Determine level of dataset */ - level = symbol_mapping[HDrandom() % NMAPPING]; + level = symbol_mapping[rand() % NMAPPING]; /* Determine the offset of the level */ - offset = (unsigned)(HDrandom() % (int)symbol_count[level]); + offset = (unsigned)(rand() % (int)symbol_count[level]); return &symbol_info[level][offset]; } /* end choose_dataset() */ diff --git a/test/swmr_generator.c b/test/swmr_generator.c index 0259a30c66c..f66ab03cd52 100644 --- a/test/swmr_generator.c +++ b/test/swmr_generator.c @@ -195,7 +195,7 @@ gen_skeleton(const char *filename, bool verbose, bool swmr_write, int comp_level * moved out of chunk #0 of the object header * (Set to true for every fourth dataset) */ - move_dataspace_message = !(HDrandom() % 4); + move_dataspace_message = !(rand() % 4); if (move_dataspace_message) { unsigned chunk_num; /* Object header chunk # for dataspace message */ @@ -336,7 +336,7 @@ main(int argc, char *argv[]) HDgettimeofday(&t, NULL); random_seed = (unsigned)(t.tv_usec); } /* end if */ - HDsrandom(random_seed); + srand(random_seed); /* ALWAYS emit the random seed for possible debugging */ fprintf(stderr, "Using generator random seed (used in sparse test only): %u\n", random_seed); diff --git a/test/swmr_reader.c b/test/swmr_reader.c index 91057703e27..93ba920f73c 100644 --- a/test/swmr_reader.c +++ b/test/swmr_reader.c @@ -228,7 +228,7 @@ read_records(const char *filename, bool verbose, FILE *verbose_file, unsigned ra /* Determine the offset of the symbol, within level 0 symbols */ /* (level 0 symbols are the most common symbols) */ - offset = (unsigned)((unsigned)HDrandom() % symbol_count[0]); + offset = (unsigned)((unsigned)rand() % symbol_count[0]); sym_com[v] = &symbol_info[0][offset]; /* Emit informational message */ @@ -475,7 +475,7 @@ main(int argc, char *argv[]) HDgettimeofday(&t, NULL); random_seed = (unsigned)(t.tv_usec); } /* end if */ - HDsrandom(random_seed); + srand(random_seed); /* Open output file */ if (verbose) { diff --git a/test/swmr_remove_reader.c b/test/swmr_remove_reader.c index 8cf22c3debc..ee5a4df2a7f 100644 --- a/test/swmr_remove_reader.c +++ b/test/swmr_remove_reader.c @@ -108,7 +108,7 @@ check_dataset(hid_t fid, unsigned verbose, const char *sym_name, symbol_t *recor if (snpoints > 0) { /* Choose a random record in the dataset, choosing the last record half * the time */ - start[1] = (hsize_t)(HDrandom() % (snpoints * 2)); + start[1] = (hsize_t)(rand() % (snpoints * 2)); if (start[1] > (hsize_t)(snpoints - 1)) start[1] = (hsize_t)(snpoints - 1); if (H5Sselect_hyperslab(file_sid, H5S_SELECT_SET, start, NULL, count, NULL) < 0) @@ -223,7 +223,7 @@ read_records(const char *filename, unsigned verbose, unsigned long nseconds, uns /* Determine the offset of the symbol, within level 0 symbols */ /* (level 0 symbols are the most common symbols) */ - offset = (unsigned)HDrandom() % symbol_count[0]; + offset = (unsigned)rand() % symbol_count[0]; sym_com[v] = &symbol_info[0][offset]; /* Emit informational message */ @@ -466,7 +466,7 @@ main(int argc, char *argv[]) HDgettimeofday(&t, NULL); random_seed = (unsigned)(t.tv_usec); } /* end if */ - HDsrandom(random_seed); + srand(random_seed); /* ALWAYS emit the random seed for possible debugging */ fprintf(stderr, "Using reader random seed: %u\n", random_seed); diff --git a/test/swmr_remove_writer.c b/test/swmr_remove_writer.c index f0d531d30a0..7b4eaeb29ef 100644 --- a/test/swmr_remove_writer.c +++ b/test/swmr_remove_writer.c @@ -158,7 +158,7 @@ remove_records(hid_t fid, unsigned verbose, unsigned long nshrinks, unsigned lon symbol = choose_dataset(); /* Shrink the dataset's dataspace */ - remove_size = (hsize_t)HDrandom() % MAX_REMOVE_SIZE + 1; + remove_size = (hsize_t)rand() % MAX_REMOVE_SIZE + 1; if (remove_size > symbol->nrecords) symbol->nrecords = 0; else @@ -297,7 +297,7 @@ main(int argc, char *argv[]) HDgettimeofday(&t, NULL); random_seed = (unsigned)(t.tv_usec); } /* end if */ - HDsrandom(random_seed); + srand(random_seed); /* ALWAYS emit the random seed for possible debugging */ fprintf(stderr, "Using writer random seed: %u\n", random_seed); diff --git a/test/swmr_sparse_reader.c b/test/swmr_sparse_reader.c index 695ca273b40..d2771e83618 100644 --- a/test/swmr_sparse_reader.c +++ b/test/swmr_sparse_reader.c @@ -106,7 +106,7 @@ check_dataset(hid_t fid, unsigned verbose, const symbol_info_t *symbol, symbol_t /* Choose the random record in the dataset (will be the same as chosen by * the writer) */ - start[1] = (hsize_t)HDrandom() % symbol->nrecords; + start[1] = (hsize_t)rand() % symbol->nrecords; if (H5Sselect_hyperslab(file_sid, H5S_SELECT_SET, start, NULL, count, NULL) < 0) return -1; @@ -205,7 +205,7 @@ read_records(const char *filename, unsigned verbose, unsigned long nrecords, uns return -1; if (H5Aclose(aid) < 0) return -1; - HDsrandom(seed); + srand(seed); /* Reset the record */ /* (record's 'info' field might need to change for each record written, also) */ diff --git a/test/swmr_sparse_writer.c b/test/swmr_sparse_writer.c index 88d0b51daac..4662d027ee1 100644 --- a/test/swmr_sparse_writer.c +++ b/test/swmr_sparse_writer.c @@ -102,7 +102,7 @@ open_skeleton(const char *filename, unsigned verbose) return -1; if (H5Aclose(aid) < 0) return -1; - HDsrandom(seed); + srand(seed); /* Open the datasets */ for (u = 0; u < NLEVELS; u++) @@ -208,7 +208,7 @@ add_records(hid_t fid, unsigned verbose, unsigned long nrecords, unsigned long f } /* end else */ /* Get the coordinate to write */ - start[1] = (hsize_t)HDrandom() % symbol->nrecords; + start[1] = (hsize_t)rand() % symbol->nrecords; /* Set the record's ID (equal to its position) */ record.rec_id = start[1]; diff --git a/test/swmr_start_write.c b/test/swmr_start_write.c index 6254da8b8c9..575e8b67baf 100644 --- a/test/swmr_start_write.c +++ b/test/swmr_start_write.c @@ -442,7 +442,7 @@ main(int argc, char *argv[]) HDgettimeofday(&t, NULL); random_seed = (unsigned)(t.tv_usec); } /* end if */ - HDsrandom(random_seed); + srand(random_seed); /* Open output file */ if (verbose) { diff --git a/test/swmr_writer.c b/test/swmr_writer.c index 7fe1a31284a..5ef6afc50e5 100644 --- a/test/swmr_writer.c +++ b/test/swmr_writer.c @@ -350,7 +350,7 @@ main(int argc, char *argv[]) HDgettimeofday(&t, NULL); random_seed = (unsigned)(t.tv_usec); } /* end if */ - HDsrandom(random_seed); + srand(random_seed); /* Open output file */ if (verbose) { diff --git a/test/tid.c b/test/tid.c index ccc61ba854d..da8700f4f74 100644 --- a/test/tid.c +++ b/test/tid.c @@ -638,7 +638,7 @@ rct_free_cb(void *_obj, void H5_ATTR_UNUSED **_ctx) * and then scanning through the list to find that nth unfreed * object. */ - remove_nth = HDrandom() % obj->list->remaining; + remove_nth = rand() % obj->list->remaining; for (i = 0; i < obj->list->count; i++) if (obj->list->objects[i].nfrees == 0) { if (remove_nth == 0) @@ -727,7 +727,7 @@ test_remove_clear_type(void) /* The number of objects used is a random number between the min and max */ obj_list.count = obj_list.remaining = - RCT_MIN_NOBJS + (HDrandom() % (long)(RCT_MAX_NOBJS - RCT_MIN_NOBJS + 1)); + RCT_MIN_NOBJS + (rand() % (long)(RCT_MAX_NOBJS - RCT_MIN_NOBJS + 1)); /* Create the actual objects */ for (j = 0; j < obj_list.count; j++) { @@ -744,7 +744,7 @@ test_remove_clear_type(void) goto error; /* Bump the reference count by 1 (to 2) 50% of the time */ - if (HDrandom() % 2) { + if (rand() % 2) { ret = H5Iinc_ref(objects[j].id); CHECK(ret, FAIL, "H5Iinc_ref"); if (ret == FAIL) @@ -1373,7 +1373,7 @@ void test_ids(void) { /* Set the random # seed */ - HDsrandom((unsigned)time(NULL)); + srand((unsigned)time(NULL)); if (basic_id_test() < 0) TestErrPrintf("Basic ID test failed\n"); diff --git a/test/tselect.c b/test/tselect.c index b545eec0324..5167aba7e06 100644 --- a/test/tselect.c +++ b/test/tselect.c @@ -6318,7 +6318,6 @@ test_select_hyper_union_random_5d(hid_t read_plist) herr_t ret; /* Generic return value */ hssize_t npoints, /* Number of elements in file selection */ npoints2; /* Number of elements in memory selection */ - unsigned seed; /* Random number seed for each test */ unsigned test_num; /* Count of tests being executed */ /* Output message about test being performed */ @@ -6362,16 +6361,15 @@ test_select_hyper_union_random_5d(hid_t read_plist) CHECK(sid2, FAIL, "H5Screate_simple"); /* Get initial random # seed */ - seed = (unsigned)time(NULL); - HDsrandom(seed); + srand((unsigned)time(NULL)); /* Crunch through a bunch of random hyperslab reads from the file dataset */ for (test_num = 0; test_num < NRAND_HYPER; test_num++) { for (i = 0; i < NHYPERSLABS; i++) { /* Select random hyperslab location & size for selection */ for (j = 0; j < SPACE5_RANK; j++) { - start[j] = ((hsize_t)HDrandom() % dims1[j]); - count[j] = (((hsize_t)HDrandom() % (dims1[j] - start[j])) + 1); + start[j] = ((hsize_t)rand() % dims1[j]); + count[j] = (((hsize_t)rand() % (dims1[j] - start[j])) + 1); } /* Select hyperslab */ @@ -6379,7 +6377,7 @@ test_select_hyper_union_random_5d(hid_t read_plist) NULL); CHECK(ret, FAIL, "H5Sselect_hyperslab"); if (ret < 0) { - TestErrPrintf("Random hyperslabs for seed %u failed!\n", seed); + TestErrPrintf("Random hyperslabs failed!\n"); break; } } @@ -6401,7 +6399,7 @@ test_select_hyper_union_random_5d(hid_t read_plist) ret = H5Dread(dataset, H5T_NATIVE_INT, sid2, sid1, read_plist, rbuf); CHECK(ret, FAIL, "H5Dread"); if (ret < 0) { - TestErrPrintf("Random hyperslabs for seed %u failed!\n", seed); + TestErrPrintf("Random hyperslabs failed!\n"); break; } @@ -6409,7 +6407,7 @@ test_select_hyper_union_random_5d(hid_t read_plist) tbuf = rbuf; ret = H5Diterate(wbuf, H5T_NATIVE_INT, sid1, test_select_hyper_iter2, &tbuf); if (ret < 0) { - TestErrPrintf("Random hyperslabs for seed %u failed!\n", seed); + TestErrPrintf("Random hyperslabs failed!\n"); break; } diff --git a/test/tskiplist.c b/test/tskiplist.c index 4c76321047f..25ee35c0418 100644 --- a/test/tskiplist.c +++ b/test/tskiplist.c @@ -55,10 +55,9 @@ tst_rev_sort(const void *i1, const void *i2) static void test_skiplist_init(void) { - time_t curr_time; /* Current time, for seeding random number generator */ - int new_val; /* New value to insert */ - unsigned found; /* Flag to indicate value was inserted already */ - size_t u, v; /* Local index variables */ + int new_val; /* New value to insert */ + unsigned found; /* Flag to indicate value was inserted already */ + size_t u, v; /* Local index variables */ /* Allocate arrays */ rand_num = (int *)malloc(sizeof(int) * NUM_ELEMS); @@ -69,8 +68,7 @@ test_skiplist_init(void) CHECK_PTR(rev_sort_rand_num, "malloc"); /* Initialize random number seed */ - curr_time = time(NULL); - HDsrandom((unsigned)curr_time); + srand((unsigned)time(NULL)); /* Create randomized set of numbers */ for (u = 0; u < NUM_ELEMS; u++) { @@ -79,7 +77,7 @@ test_skiplist_init(void) found = 0; /* Generate random numbers from -5000 to 5000 */ - new_val = (int)(HDrandom() % 10001) - 5001; + new_val = (int)(rand() % 10001) - 5001; /* Check if the value is already in the array */ for (v = 0; v < u; v++) diff --git a/test/tunicode.c b/test/tunicode.c index d3baf801692..62ce82da804 100644 --- a/test/tunicode.c +++ b/test/tunicode.c @@ -815,14 +815,14 @@ test_unicode(void) MESSAGE(5, ("Testing UTF-8 Encoding\n")); /* Create a random string with length NUM_CHARS */ - HDsrandom((unsigned)time(NULL)); + srand((unsigned)time(NULL)); memset(test_string, 0, sizeof(test_string)); for (x = 0; x < NUM_CHARS; x++) { /* We need to avoid unprintable characters (codes 0-31) and the * . and / characters, since they aren't allowed in path names. */ - unicode_point = (unsigned)(HDrandom() % (MAX_CODE_POINT - 32)) + 32; + unicode_point = (unsigned)(rand() % (MAX_CODE_POINT - 32)) + 32; if (unicode_point != 46 && unicode_point != 47) cur_pos = write_char(unicode_point, test_string, cur_pos); } diff --git a/test/unlink.c b/test/unlink.c index 62c7e61a1b4..a722c21fbc3 100644 --- a/test/unlink.c +++ b/test/unlink.c @@ -816,7 +816,7 @@ test_filespace(hid_t fapl) /* Set buffer to different random numbers each time */ for (v = 0, tmp_data = data; v < (FILESPACE_DIM0 * FILESPACE_DIM1 * FILESPACE_DIM2); v++) - *tmp_data++ = (int)HDrandom(); + *tmp_data++ = (int)rand(); /* Write the buffer to the dataset */ if (H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data) < 0) @@ -2906,7 +2906,7 @@ main(void) double rdcc_w0; /* Set the random # seed */ - HDsrandom((unsigned)time(NULL)); + srand((unsigned)time(NULL)); /* Open */ h5_reset(); diff --git a/test/vfd.c b/test/vfd.c index 7025de907df..9f33e0ea328 100644 --- a/test/vfd.c +++ b/test/vfd.c @@ -3461,7 +3461,7 @@ setup_rand(void) fprintf(stdout, "\n%s: predefined_seed = %d.\n\n", __func__, seed); fflush(stdout); - HDsrand(seed); + srand(seed); } else { @@ -3477,7 +3477,7 @@ setup_rand(void) fprintf(stdout, "\n%s: seed = %d.\n\n", __func__, seed); fflush(stdout); - HDsrand(seed); + srand(seed); } } diff --git a/testpar/t_cache.c b/testpar/t_cache.c index 0f845ef9b39..162b8f31679 100644 --- a/testpar/t_cache.c +++ b/testpar/t_cache.c @@ -2883,7 +2883,7 @@ local_pin_and_unpin_random_entries(H5F_t *file_ptr, int min_idx, int max_idx, in assert(0 <= min_count); assert(min_count < max_count); - count = (HDrand() % (max_count - min_count)) + min_count; + count = (rand() % (max_count - min_count)) + min_count; assert(min_count <= count); assert(count <= max_count); @@ -2892,7 +2892,7 @@ local_pin_and_unpin_random_entries(H5F_t *file_ptr, int min_idx, int max_idx, in local_pin_random_entry(file_ptr, min_idx, max_idx); } - count = (HDrand() % (max_count - min_count)) + min_count; + count = (rand() % (max_count - min_count)) + min_count; assert(min_count <= count); assert(count <= max_count); @@ -2938,7 +2938,7 @@ local_pin_random_entry(H5F_t *file_ptr, int min_idx, int max_idx) assert(max_idx < virt_num_data_entries); do { - idx = (HDrand() % (max_idx - min_idx)) + min_idx; + idx = (rand() % (max_idx - min_idx)) + min_idx; assert(min_idx <= idx); assert(idx <= max_idx); } while (data[idx].global_pinned || data[idx].local_pinned); @@ -3055,7 +3055,7 @@ lock_and_unlock_random_entries(H5F_t *file_ptr, int min_idx, int max_idx, int mi assert(0 <= min_count); assert(min_count < max_count); - count = (HDrand() % (max_count - min_count)) + min_count; + count = (rand() % (max_count - min_count)) + min_count; assert(min_count <= count); assert(count <= max_count); @@ -3093,7 +3093,7 @@ lock_and_unlock_random_entry(H5F_t *file_ptr, int min_idx, int max_idx) assert(max_idx < NUM_DATA_ENTRIES); assert(max_idx < virt_num_data_entries); - idx = (HDrand() % (max_idx - min_idx)) + min_idx; + idx = (rand() % (max_idx - min_idx)) + min_idx; assert(min_idx <= idx); assert(idx <= max_idx); @@ -3933,7 +3933,7 @@ setup_rand(void) seed = predefined_seeds[world_mpi_rank]; fprintf(stdout, "%d:%s: predefined_seed = %d.\n", world_mpi_rank, __func__, seed); fflush(stdout); - HDsrand(seed); + srand(seed); } else { @@ -3950,7 +3950,7 @@ setup_rand(void) fprintf(stdout, "%d:%s: seed = %d.\n", world_mpi_rank, __func__, seed); fflush(stdout); } - HDsrand(seed); + srand(seed); } } diff --git a/testpar/t_pmulti_dset.c b/testpar/t_pmulti_dset.c index a61e1b4dcc4..c3c65c62479 100644 --- a/testpar/t_pmulti_dset.c +++ b/testpar/t_pmulti_dset.c @@ -267,7 +267,7 @@ test_pmdset(size_t niter, unsigned flags) for (i = 0; i < niter; i++) { /* Determine number of datasets */ ndsets = (flags & MDSET_FLAG_MLAYOUT) ? 3 - : (flags & MDSET_FLAG_MDSET) ? (size_t)((size_t)HDrandom() % max_dsets) + 1 + : (flags & MDSET_FLAG_MDSET) ? (size_t)((size_t)rand() % max_dsets) + 1 : 1; /* Create file */ @@ -280,16 +280,16 @@ test_pmdset(size_t niter, unsigned flags) (flags & MDSET_FLAG_CHUNK) || ((flags & MDSET_FLAG_MLAYOUT) && (j == 1 || j == 2)); /* Generate file dataspace */ - dset_dims[j][0] = (hsize_t)((HDrandom() % MAX_DSET_X) + 1); - dset_dims[j][1] = (hsize_t)((HDrandom() % MAX_DSET_Y) + 1); + dset_dims[j][0] = (hsize_t)((rand() % MAX_DSET_X) + 1); + dset_dims[j][1] = (hsize_t)((rand() % MAX_DSET_Y) + 1); if ((file_space_ids[j] = H5Screate_simple(2, dset_dims[j], use_chunk ? max_dims : NULL)) < 0) T_PMD_ERROR; /* Generate chunk if called for by configuration (multi layout uses chunked for datasets * 1 and 2) */ if (use_chunk) { - chunk_dims[0] = (hsize_t)((HDrandom() % MAX_CHUNK_X) + 1); - chunk_dims[1] = (hsize_t)((HDrandom() % MAX_CHUNK_Y) + 1); + chunk_dims[0] = (hsize_t)((rand() % MAX_CHUNK_X) + 1); + chunk_dims[1] = (hsize_t)((rand() % MAX_CHUNK_Y) + 1); if (H5Pset_chunk(dcpl_id[j], 2, chunk_dims) < 0) T_PMD_ERROR; } /* end if */ @@ -297,10 +297,10 @@ test_pmdset(size_t niter, unsigned flags) /* Create dataset */ /* If MDSET_FLAG_TCONV is set, use a different datatype with 50% probability, so * some datasets require type conversion and others do not */ - if ((dset_ids[j] = H5Dcreate2(file_id, dset_name[j], - (flags & MDSET_FLAG_TCONV && HDrandom() % 2) ? H5T_NATIVE_LONG - : H5T_NATIVE_UINT, - file_space_ids[j], H5P_DEFAULT, dcpl_id[j], H5P_DEFAULT)) < 0) + if ((dset_ids[j] = + H5Dcreate2(file_id, dset_name[j], + (flags & MDSET_FLAG_TCONV && rand() % 2) ? H5T_NATIVE_LONG : H5T_NATIVE_UINT, + file_space_ids[j], H5P_DEFAULT, dcpl_id[j], H5P_DEFAULT)) < 0) T_PMD_ERROR; } /* end for */ @@ -325,7 +325,7 @@ test_pmdset(size_t niter, unsigned flags) /* Perform read/write operations */ for (j = 0; j < OPS_PER_FILE; j++) { /* Decide whether to read or write */ - do_read = (bool)(HDrandom() % 2); + do_read = (bool)(rand() % 2); /* Barrier to ensure processes have finished the previous operation */ @@ -387,9 +387,9 @@ test_pmdset(size_t niter, unsigned flags) (int)((unsigned)max_dsets * MAX_DSET_X * MAX_DSET_Y) * ((int)l - (int)mpi_rank); /* Decide whether to do a hyperslab or point selection */ - if (HDrandom() % 2) { + if (rand() % 2) { /* Hyperslab */ - size_t nhs = (size_t)((HDrandom() % MAX_HS) + 1); /* Number of hyperslabs */ + size_t nhs = (size_t)((rand() % MAX_HS) + 1); /* Number of hyperslabs */ size_t max_hs_x = (MAX_HS_X <= dset_dims[k][0]) ? MAX_HS_X : dset_dims[k][0]; /* Determine maximum hyperslab size in X */ @@ -401,14 +401,14 @@ test_pmdset(size_t niter, unsigned flags) overlap = true; for (n = 0; overlap && (n < MAX_SEL_RETRIES); n++) { /* Generate hyperslab */ - count[m][0] = (hsize_t)(((hsize_t)HDrandom() % max_hs_x) + 1); - count[m][1] = (hsize_t)(((hsize_t)HDrandom() % max_hs_y) + 1); + count[m][0] = (hsize_t)(((hsize_t)rand() % max_hs_x) + 1); + count[m][1] = (hsize_t)(((hsize_t)rand() % max_hs_y) + 1); start[m][0] = (count[m][0] == dset_dims[k][0]) ? 0 - : (hsize_t)HDrandom() % (dset_dims[k][0] - count[m][0] + 1); + : (hsize_t)rand() % (dset_dims[k][0] - count[m][0] + 1); start[m][1] = (count[m][1] == dset_dims[k][1]) ? 0 - : (hsize_t)HDrandom() % (dset_dims[k][1] - count[m][1] + 1); + : (hsize_t)rand() % (dset_dims[k][1] - count[m][1] + 1); /* If writing, check for overlap with other processes */ overlap = false; @@ -460,8 +460,7 @@ test_pmdset(size_t niter, unsigned flags) } /* end if */ else { /* Point selection */ - size_t npoints = - (size_t)(((size_t)HDrandom() % MAX_POINTS) + 1); /* Number of points */ + size_t npoints = (size_t)(((size_t)rand() % MAX_POINTS) + 1); /* Number of points */ /* Reset dataset usage array if reading, since in this case we don't care * about overlapping selections between processes */ @@ -473,8 +472,8 @@ test_pmdset(size_t niter, unsigned flags) overlap = true; for (n = 0; overlap && (n < MAX_SEL_RETRIES); n++) { /* Generate point */ - points[2 * m] = (unsigned)((hsize_t)HDrandom() % dset_dims[k][0]); - points[(2 * m) + 1] = (unsigned)((hsize_t)HDrandom() % dset_dims[k][1]); + points[2 * m] = (unsigned)((hsize_t)rand() % dset_dims[k][0]); + points[(2 * m) + 1] = (unsigned)((hsize_t)rand() % dset_dims[k][1]); /* Check for overlap with other processes (write) or this process * (always) */ @@ -665,7 +664,7 @@ main(int argc, char *argv[]) /* Seed random number generator with shared seed (so all ranks generate the * same sequence) */ - HDsrandom(seed); + srand(seed); /* Fill dset_name array */ for (i = 0; i < MAX_DSETS; i++) { diff --git a/testpar/t_select_io_dset.c b/testpar/t_select_io_dset.c index 9d3f1205051..6382aed45b3 100644 --- a/testpar/t_select_io_dset.c +++ b/testpar/t_select_io_dset.c @@ -1588,7 +1588,7 @@ test_multi_dsets_no_bkg(hid_t fid, unsigned chunked, unsigned dtrans, unsigned s mwbuf ? "mwbuf" : "nomwbuf"); /* Flip a coin to see if we're doing type conversion */ - tconv = HDrandom() % 2; + tconv = rand() % 2; if (tconv) any_tconv = true; @@ -2079,7 +2079,7 @@ test_multi_dsets_cmpd_with_bkg(hid_t fid, unsigned chunked, unsigned select, uns } /* Case c */ - mm = HDrandom() % (int)ndsets; + mm = rand() % (int)ndsets; if (!mm) mm++; @@ -2720,7 +2720,7 @@ test_multi_dsets_conv_sel_empty(hid_t fid, unsigned chunked, unsigned dtrans, un } else { if ((dset_dids[i] = - H5Dcreate2(fid, dset_names[i], ((HDrandom() % 2) ? H5T_NATIVE_LLONG : H5T_NATIVE_SHORT), + H5Dcreate2(fid, dset_names[i], ((rand() % 2) ? H5T_NATIVE_LLONG : H5T_NATIVE_SHORT), file_sids[i], H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) P_TEST_ERROR; } @@ -2790,7 +2790,7 @@ test_multi_dsets_conv_sel_empty(hid_t fid, unsigned chunked, unsigned dtrans, un * process 0: get 0 row; other processes: hyperslab */ - mm = HDrandom() % (int)ndsets; + mm = rand() % (int)ndsets; if (mm == 0) mm++; @@ -3169,7 +3169,7 @@ test_multi_dsets_all(int niter, hid_t fid, unsigned chunked, unsigned select, un if ((mem_sids[i] = H5Screate_simple(1, block, NULL)) < 0) P_TEST_ERROR; - mm = HDrandom() % (int)ndsets; + mm = rand() % (int)ndsets; if (mm == 0) { dset_types[i] = DSET_WITH_NO_CONV; snprintf(dset_names[i], sizeof(dset_names[i]), "multi_all_nconv_dset%d_%s_%s_%s", i, diff --git a/tools/test/perform/overhead.c b/tools/test/perform/overhead.c index ecdecb34d54..721124c05bb 100644 --- a/tools/test/perform/overhead.c +++ b/tools/test/perform/overhead.c @@ -206,7 +206,7 @@ test(fill_t fill_style, const double splits[], bool verbose, bool use_rdcc) hs_start[0] = k % 2 ? (k / 2) : (hsize_t)((hssize_t)cur_size[0] - (hssize_t)(k / 2)); break; case FILL_RANDOM: - for (j = HDrand() % (int)cur_size[0]; had[j]; j = (j + 1) % (int)cur_size[0]) + for (j = rand() % (int)cur_size[0]; had[j]; j = (j + 1) % (int)cur_size[0]) /*void*/; hs_start[0] = (hsize_t)j; had[j] = 1; diff --git a/tools/test/perform/zip_perf.c b/tools/test/perform/zip_perf.c index 76e455f4ab5..8f33a86bf42 100644 --- a/tools/test/perform/zip_perf.c +++ b/tools/test/perform/zip_perf.c @@ -337,7 +337,7 @@ fill_with_random_data(Bytef *src, uLongf src_len) fprintf(stdout, "Using random() for random data\n"); for (u = 0; u < src_len; ++u) - src[u] = (Bytef)(0xff & HDrandom()); + src[u] = (Bytef)(0xff & rand()); } if (compress_percent) {