未验证 提交 f0445edf 编写于 作者: wafwerar's avatar wafwerar 提交者: GitHub

Merge pull request #10663 from taosdata/fix/ZhiqiangWang/TD-13765-redefie-rand-api

[TD-13765]<fix>: redefine rand api.
......@@ -377,7 +377,7 @@ void printConf(SRaftServerConfig *pConf) {
int main(int argc, char **argv) {
srand(time(NULL));
taosSeedRand(time(NULL));
int32_t ret;
exe_name = argv[0];
......
......@@ -132,7 +132,7 @@ static void proposeValue(struct raft *r) {
buf.base = raft_malloc(buf.len);
// mock ts value
int vid = rand() % VNODE_COUNT;
int vid = taosRand() % VNODE_COUNT;
snprintf(buf.base, buf.len, "%d:value_%ld", vid, time(NULL));
printf("propose value: %s \n", (char*)buf.base);
......@@ -174,7 +174,7 @@ void usage() {
}
int main(int argc, char **argv) {
srand(time(NULL));
taosSeedRand(time(NULL));
exe_name = argv[0];
if (argc < 2) {
......
......@@ -19,7 +19,7 @@ void shuffle(char**lines, size_t n)
size_t i;
for (i = 0; i < n - 1; i++)
{
size_t j = i + rand() / (RAND_MAX / (n - i) + 1);
size_t j = i + taosRand() / (RAND_MAX / (n - i) + 1);
char* t = lines[j];
lines[j] = lines[i];
lines[i] = t;
......
......@@ -20,7 +20,16 @@
extern "C" {
#endif
// If the error is in a third-party library, place this header file under the third-party library header file.
#ifndef ALLOW_FORBID_FUNC
#define rand RAND_FUNC_TAOS_FORBID
#define srand SRAND_FUNC_TAOS_FORBID
#define rand_r RANDR_FUNC_TAOS_FORBID
#endif
void taosSeedRand(uint32_t seed);
uint32_t taosRand(void);
uint32_t taosRandR(uint32_t *pSeed);
void taosRandStr(char* str, int32_t size);
uint32_t taosSafeRand(void);
......
......@@ -208,7 +208,7 @@ void taos_init_imp(void) {
atexit(taos_cleanup);
errno = TSDB_CODE_SUCCESS;
srand(taosGetTimestampSec());
taosSeedRand(taosGetTimestampSec());
deltaToUtcInitOnce();
......
......@@ -168,10 +168,10 @@ TEST_F(TqMetaUpdateAppendTest, intxnPersist) {
}
TEST_F(TqMetaUpdateAppendTest, multiplePage) {
srand(0);
taosSeedRand(0);
std::vector<int> v;
for (int i = 0; i < 1000; i++) {
v.push_back(rand());
v.push_back(taosRand());
Foo foo;
foo.a = v[i];
tqHandleCopyPut(pMeta, i, &foo, sizeof(Foo));
......@@ -202,10 +202,10 @@ TEST_F(TqMetaUpdateAppendTest, multiplePage) {
}
TEST_F(TqMetaUpdateAppendTest, multipleRewrite) {
srand(0);
taosSeedRand(0);
std::vector<int> v;
for (int i = 0; i < 1000; i++) {
v.push_back(rand());
v.push_back(taosRand());
Foo foo;
foo.a = v[i];
tqHandleCopyPut(pMeta, i, &foo, sizeof(Foo));
......@@ -213,14 +213,14 @@ TEST_F(TqMetaUpdateAppendTest, multipleRewrite) {
for (int i = 0; i < 500; i++) {
tqHandleCommit(pMeta, i);
v[i] = rand();
v[i] = taosRand();
Foo foo;
foo.a = v[i];
tqHandleCopyPut(pMeta, i, &foo, sizeof(Foo));
}
for (int i = 500; i < 1000; i++) {
v[i] = rand();
v[i] = taosRand();
Foo foo;
foo.a = v[i];
tqHandleCopyPut(pMeta, i, &foo, sizeof(Foo));
......@@ -235,7 +235,7 @@ TEST_F(TqMetaUpdateAppendTest, multipleRewrite) {
ASSERT(pMeta);
for (int i = 500; i < 1000; i++) {
v[i] = rand();
v[i] = taosRand();
Foo foo;
foo.a = v[i];
tqHandleCopyPut(pMeta, i, &foo, sizeof(Foo));
......@@ -250,10 +250,10 @@ TEST_F(TqMetaUpdateAppendTest, multipleRewrite) {
}
TEST_F(TqMetaUpdateAppendTest, dupCommit) {
srand(0);
taosSeedRand(0);
std::vector<int> v;
for (int i = 0; i < 1000; i++) {
v.push_back(rand());
v.push_back(taosRand());
Foo foo;
foo.a = v[i];
tqHandleCopyPut(pMeta, i, &foo, sizeof(Foo));
......
......@@ -723,7 +723,7 @@ void *ctgTestGetDbVgroupThread(void *param) {
}
if (ctgTestEnableSleep) {
usleep(rand() % 5);
usleep(taosRand() % 5);
}
if (++n % ctgTestPrintNum == 0) {
printf("Get:%d\n", n);
......@@ -747,7 +747,7 @@ void *ctgTestSetSameDbVgroupThread(void *param) {
}
if (ctgTestEnableSleep) {
usleep(rand() % 5);
usleep(taosRand() % 5);
}
if (++n % ctgTestPrintNum == 0) {
printf("Set:%d\n", n);
......@@ -771,7 +771,7 @@ void *ctgTestSetDiffDbVgroupThread(void *param) {
}
if (ctgTestEnableSleep) {
usleep(rand() % 5);
usleep(taosRand() % 5);
}
if (++n % ctgTestPrintNum == 0) {
printf("Set:%d\n", n);
......@@ -801,7 +801,7 @@ void *ctgTestGetCtableMetaThread(void *param) {
tfree(tbMeta);
if (ctgTestEnableSleep) {
usleep(rand() % 5);
usleep(taosRand() % 5);
}
if (++n % ctgTestPrintNum == 0) {
......@@ -838,7 +838,7 @@ void *ctgTestSetCtableMetaThread(void *param) {
}
if (ctgTestEnableSleep) {
usleep(rand() % 5);
usleep(taosRand() % 5);
}
if (++n % ctgTestPrintNum == 0) {
printf("Set:%d\n", n);
......
......@@ -61,7 +61,7 @@ typedef enum SResultTsInterpType {
#if 0
static UNUSED_FUNC void *u_malloc (size_t __size) {
uint32_t v = rand();
uint32_t v = taosRand();
if (v % 1000 <= 0) {
return NULL;
......@@ -71,7 +71,7 @@ static UNUSED_FUNC void *u_malloc (size_t __size) {
}
static UNUSED_FUNC void* u_calloc(size_t num, size_t __size) {
uint32_t v = rand();
uint32_t v = taosRand();
if (v % 1000 <= 0) {
return NULL;
} else {
......@@ -80,7 +80,7 @@ static UNUSED_FUNC void* u_calloc(size_t num, size_t __size) {
}
static UNUSED_FUNC void* u_realloc(void* p, size_t __size) {
uint32_t v = rand();
uint32_t v = taosRand();
if (v % 5 <= 1) {
return NULL;
} else {
......
......@@ -869,7 +869,7 @@ TEST(testCase, external_sort_Test) {
#if 0
su* v = static_cast<su*>(calloc(1000000, sizeof(su)));
for(int32_t i = 0; i < 1000000; ++i) {
v[i].v = rand();
v[i].v = taosRand();
v[i].c = static_cast<char*>(malloc(4));
*(int32_t*) v[i].c = i;
}
......@@ -882,7 +882,7 @@ TEST(testCase, external_sort_Test) {
return;
#endif
srand(time(NULL));
taosSeedRand(time(NULL));
SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder));
SOrder o = {0};
......@@ -943,7 +943,7 @@ TEST(testCase, external_sort_Test) {
}
TEST(testCase, sorted_merge_Test) {
srand(time(NULL));
taosSeedRand(time(NULL));
SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder));
SOrder o = {0};
......@@ -1015,7 +1015,7 @@ TEST(testCase, sorted_merge_Test) {
}
TEST(testCase, time_interval_Operator_Test) {
srand(time(NULL));
taosSeedRand(time(NULL));
SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder));
SOrder o = {0};
......
......@@ -25,7 +25,7 @@
#pragma GCC diagnostic ignored "-Wsign-compare"
TEST(testCase, linear_hash_Tests) {
srand(time(NULL));
taosSeedRand(time(NULL));
_hash_fn_t fn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT);
#if 0
......
......@@ -699,7 +699,7 @@ class IndexObj {
for (int i = 0; i < numOfTable; i++) {
for (int k = 0; k < 10 && k < colVal.size(); k++) {
// opt
tColVal[rand() % colValSize] = 'a' + k % 26;
tColVal[taosRand() % colValSize] = 'a' + k % 26;
}
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
tColVal.c_str(), tColVal.size());
......
......@@ -266,7 +266,7 @@ int32_t qwtCreateExecTask(void* tsdb, int32_t vgId, struct SSubplan* pPlan, qTas
int32_t idx = abs((++qwtTestCaseIdx) % qwtTestCaseNum);
qwtTestSinkBlockNum = 0;
qwtTestSinkMaxBlockNum = rand() % 100 + 1;
qwtTestSinkMaxBlockNum = taosRand() % 100 + 1;
qwtTestSinkQueryEnd = false;
if (0 == idx) {
......@@ -295,15 +295,15 @@ int32_t qwtExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t *useconds) {
} else {
if (qwtTestSinkQueryEnd) {
*pRes = NULL;
*useconds = rand() % 10;
*useconds = taosRand() % 10;
return 0;
}
endExec = rand() % 5;
endExec = taosRand() % 5;
int32_t runTime = 0;
if (qwtTestEnableSleep && qwtTestMaxExecTaskUsec > 0) {
runTime = rand() % qwtTestMaxExecTaskUsec;
runTime = taosRand() % qwtTestMaxExecTaskUsec;
}
if (qwtTestEnableSleep) {
......@@ -314,10 +314,10 @@ int32_t qwtExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t *useconds) {
if (endExec) {
*pRes = (SSDataBlock*)calloc(1, sizeof(SSDataBlock));
(*pRes)->info.rows = rand() % 1000;
(*pRes)->info.rows = taosRand() % 1000;
} else {
*pRes = NULL;
*useconds = rand() % 10;
*useconds = taosRand() % 10;
}
}
......@@ -376,7 +376,7 @@ void qwtGetDataLength(DataSinkHandle handle, int32_t* pLen, bool* pQueryEnd) {
taosWLockLatch(&qwtTestSinkLock);
if (qwtTestSinkBlockNum > 0) {
*pLen = rand() % 100 + 1;
*pLen = taosRand() % 100 + 1;
qwtTestSinkBlockNum--;
} else {
*pLen = 0;
......@@ -392,7 +392,7 @@ void qwtGetDataLength(DataSinkHandle handle, int32_t* pLen, bool* pQueryEnd) {
int32_t qwtGetDataBlock(DataSinkHandle handle, SOutputData* pOutput) {
taosWLockLatch(&qwtTestSinkLock);
if (qwtTestSinkLastLen > 0) {
pOutput->numOfRows = rand() % 10 + 1;
pOutput->numOfRows = taosRand() % 10 + 1;
pOutput->compressed = 1;
pOutput->queryEnd = qwtTestSinkQueryEnd;
if (qwtTestSinkBlockNum == 0) {
......@@ -402,7 +402,7 @@ int32_t qwtGetDataBlock(DataSinkHandle handle, SOutputData* pOutput) {
} else {
pOutput->bufStatus = DS_BUF_FULL;
}
pOutput->useconds = rand() % 10 + 1;
pOutput->useconds = taosRand() % 10 + 1;
pOutput->precision = 1;
} else if (qwtTestSinkLastLen == 0) {
pOutput->numOfRows = 0;
......@@ -416,7 +416,7 @@ int32_t qwtGetDataBlock(DataSinkHandle handle, SOutputData* pOutput) {
} else {
pOutput->bufStatus = DS_BUF_FULL;
}
pOutput->useconds = rand() % 10 + 1;
pOutput->useconds = taosRand() % 10 + 1;
pOutput->precision = 1;
} else {
assert(0);
......@@ -590,7 +590,7 @@ void *queryThread(void *param) {
qwtBuildQueryReqMsg(&queryRpc);
qWorkerProcessQueryMsg(mockPointer, mgmt, &queryRpc);
if (qwtTestEnableSleep) {
usleep(rand()%5);
usleep(taosRand()%5);
}
if (++n % qwtTestPrintNum == 0) {
printf("query:%d\n", n);
......@@ -612,7 +612,7 @@ void *readyThread(void *param) {
qwtBuildReadyReqMsg(&readyMsg, &readyRpc);
code = qWorkerProcessReadyMsg(mockPointer, mgmt, &readyRpc);
if (qwtTestEnableSleep) {
usleep(rand()%5);
usleep(taosRand()%5);
}
if (++n % qwtTestPrintNum == 0) {
printf("ready:%d\n", n);
......@@ -634,7 +634,7 @@ void *fetchThread(void *param) {
qwtBuildFetchReqMsg(&fetchMsg, &fetchRpc);
code = qWorkerProcessFetchMsg(mockPointer, mgmt, &fetchRpc);
if (qwtTestEnableSleep) {
usleep(rand()%5);
usleep(taosRand()%5);
}
if (++n % qwtTestPrintNum == 0) {
printf("fetch:%d\n", n);
......@@ -656,7 +656,7 @@ void *dropThread(void *param) {
qwtBuildDropReqMsg(&dropMsg, &dropRpc);
code = qWorkerProcessDropMsg(mockPointer, mgmt, &dropRpc);
if (qwtTestEnableSleep) {
usleep(rand()%5);
usleep(taosRand()%5);
}
if (++n % qwtTestPrintNum == 0) {
printf("drop:%d\n", n);
......@@ -678,7 +678,7 @@ void *statusThread(void *param) {
qwtBuildStatusReqMsg(&statusMsg, &statusRpc);
code = qWorkerProcessStatusMsg(mockPointer, mgmt, &statusRpc);
if (qwtTestEnableSleep) {
usleep(rand()%5);
usleep(taosRand()%5);
}
if (++n % qwtTestPrintNum == 0) {
printf("status:%d\n", n);
......@@ -748,7 +748,7 @@ void *queryQueueThread(void *param) {
if (qwtTestEnableSleep && qwtTestReqMaxDelayUsec > 0) {
int32_t delay = rand() % qwtTestReqMaxDelayUsec;
int32_t delay = taosRand() % qwtTestReqMaxDelayUsec;
if (delay) {
usleep(delay);
......@@ -804,7 +804,7 @@ void *fetchQueueThread(void *param) {
taosWUnLockLatch(&qwtTestFetchQueueLock);
if (qwtTestEnableSleep && qwtTestReqMaxDelayUsec > 0) {
int32_t delay = rand() % qwtTestReqMaxDelayUsec;
int32_t delay = taosRand() % qwtTestReqMaxDelayUsec;
if (delay) {
usleep(delay);
......@@ -963,7 +963,7 @@ TEST(seqTest, randCase) {
stubSetRpcSendResponse();
stubSetCreateExecTask();
srand(time(NULL));
taosSeedRand(time(NULL));
code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, mockPointer, qwtPutReqToQueue);
ASSERT_EQ(code, 0);
......@@ -971,7 +971,7 @@ TEST(seqTest, randCase) {
int32_t t = 0;
int32_t maxr = 10001;
while (true) {
int32_t r = rand() % maxr;
int32_t r = taosRand() % maxr;
if (r >= 0 && r < maxr/5) {
printf("Query,%d\n", t++);
......@@ -1025,7 +1025,7 @@ TEST(seqTest, multithreadRand) {
stubSetStringToPlan();
stubSetRpcSendResponse();
srand(time(NULL));
taosSeedRand(time(NULL));
code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, mockPointer, qwtPutReqToQueue);
ASSERT_EQ(code, 0);
......@@ -1076,7 +1076,7 @@ TEST(rcTest, shortExecshortDelay) {
stubSetPutDataBlock();
stubSetGetDataBlock();
srand(time(NULL));
taosSeedRand(time(NULL));
qwtTestStop = false;
qwtTestQuitThreadNum = 0;
......@@ -1157,7 +1157,7 @@ TEST(rcTest, longExecshortDelay) {
stubSetPutDataBlock();
stubSetGetDataBlock();
srand(time(NULL));
taosSeedRand(time(NULL));
qwtTestStop = false;
qwtTestQuitThreadNum = 0;
......@@ -1240,7 +1240,7 @@ TEST(rcTest, shortExeclongDelay) {
stubSetPutDataBlock();
stubSetGetDataBlock();
srand(time(NULL));
taosSeedRand(time(NULL));
qwtTestStop = false;
qwtTestQuitThreadNum = 0;
......@@ -1324,7 +1324,7 @@ TEST(rcTest, dropTest) {
stubSetPutDataBlock();
stubSetGetDataBlock();
srand(time(NULL));
taosSeedRand(time(NULL));
code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, mockPointer, qwtPutReqToQueue);
ASSERT_EQ(code, 0);
......@@ -1358,7 +1358,7 @@ TEST(rcTest, dropTest) {
int main(int argc, char** argv) {
srand(time(NULL));
taosSeedRand(time(NULL));
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
......
......@@ -1286,7 +1286,7 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) {
int main(int argc, char** argv) {
srand(time(NULL));
taosSeedRand(time(NULL));
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
......
......@@ -1427,7 +1427,7 @@ TEST(columnTest, greater_and_lower) {
int main(int argc, char** argv) {
srand(time(NULL));
taosSeedRand(time(NULL));
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
......
......@@ -532,7 +532,7 @@ void* schtRunJobThread(void *aa) {
void* schtFreeJobThread(void *aa) {
while (!schtTestStop) {
usleep(rand() % 100);
usleep(taosRand() % 100);
schtFreeQueryJob(1);
}
}
......@@ -713,7 +713,7 @@ TEST(multiThread, forceFree) {
}
int main(int argc, char** argv) {
srand(time(NULL));
taosSeedRand(time(NULL));
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
......
......@@ -28,7 +28,7 @@ static void doSyncEnvStopTimer(SSyncEnv *pSyncEnv, tmr_h *pTimer);
int32_t syncEnvStart() {
int32_t ret;
srand(time(NULL));
taosSeedRand(time(NULL));
gSyncEnv = (SSyncEnv *)malloc(sizeof(SSyncEnv));
assert(gSyncEnv != NULL);
ret = doSyncEnvStart(gSyncEnv);
......
......@@ -44,7 +44,7 @@ int32_t syncIOStart(char *host, uint16_t port) {
gSyncIO = syncIOCreate(host, port);
assert(gSyncIO != NULL);
srand(time(NULL));
taosSeedRand(time(NULL));
int32_t ret = syncIOStartInternal(gSyncIO);
assert(ret == 0);
......
......@@ -95,7 +95,7 @@ void syncUtilbufCopyDeep(const SSyncBuffer* src, SSyncBuffer* dest) {
// ---- misc ----
int32_t syncUtilRand(int32_t max) { return rand() % max; }
int32_t syncUtilRand(int32_t max) { return taosRand() % max; }
int32_t syncUtilElectRandomMS() { return ELECT_TIMER_MS_MIN + syncUtilRand(ELECT_TIMER_MS_RANGE); }
......
......@@ -27,7 +27,7 @@ int tdbGnrtFileID(const char *fname, uint8_t *fileid, bool unique) {
((uint64_t *)fileid)[0] = stDev;
((uint64_t *)fileid)[1] = stIno;
if (unique) {
((uint64_t *)fileid)[2] = rand();
((uint64_t *)fileid)[2] = taosRand();
}
return 0;
......
......@@ -749,7 +749,7 @@ static SRpcConn *rpcAllocateServerConn(SRpcInfo *pRpc, SRecvInfo *pRecv) {
memcpy(pConn->user, pHead->user, tListLen(pConn->user));
pConn->pRpc = pRpc;
pConn->sid = sid;
pConn->tranId = (uint16_t)(rand() & 0xFFFF);
pConn->tranId = (uint16_t)(taosRand() & 0xFFFF);
pConn->ownId = htonl(pConn->sid);
pConn->linkUid = pHead->linkUid;
if (pRpc->afp) {
......
......@@ -300,7 +300,7 @@ TEST_F(WalKeepEnv, readHandleRead) {
ASSERT_EQ(code, 0);
}
for (int i = 0; i < 1000; i++) {
int ver = rand() % 100;
int ver = taosRand() % 100;
code = walReadWithHandle(pRead, ver);
ASSERT_EQ(code, 0);
......@@ -352,7 +352,7 @@ TEST_F(WalRetentionEnv, repairMeta1) {
ASSERT(pRead != NULL);
for (int i = 0; i < 1000; i++) {
int ver = rand() % 100;
int ver = taosRand() % 100;
code = walReadWithHandle(pRead, ver);
ASSERT_EQ(code, 0);
......@@ -382,7 +382,7 @@ TEST_F(WalRetentionEnv, repairMeta1) {
}
for (int i = 0; i < 1000; i++) {
int ver = rand() % 200;
int ver = taosRand() % 200;
code = walReadWithHandle(pRead, ver);
ASSERT_EQ(code, 0);
......
......@@ -38,7 +38,7 @@ float tsNumOfCores = 0;
int64_t tsTotalMemoryKB = 0;
void osInit() {
srand(taosSafeRand());
taosSeedRand(taosSafeRand());
taosGetSystemLocale(tsLocale, tsCharset);
taosGetSystemTimezone(tsTimezone);
taosSetSystemTimezone(tsTimezone, tsTimezone, &tsDaylight);
......
......@@ -12,7 +12,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define ALLOW_FORBID_FUNC
#define _DEFAULT_SOURCE
#include "os.h"
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
......@@ -21,8 +21,12 @@
#include <unistd.h>
#endif
void taosSeedRand(uint32_t seed) { return srand(seed); }
uint32_t taosRand(void) { return rand(); }
uint32_t taosRandR(uint32_t *pSeed) { return rand_r(pSeed); }
uint32_t taosSafeRand(void) {
TdFilePtr pFile;
int seed;
......
......@@ -32,7 +32,7 @@ void process_message(uint8_t* message_piece, uint8_t* processed_piece, key_set*
#if 0
int64_t taosDesGenKey() {
uint32_t iseed = (uint32_t)time(NULL);
srand(iseed);
taosSeedRand(iseed);
uint8_t key[8] = {0};
generate_key(key);
......
......@@ -51,7 +51,7 @@ SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint16_t keyLen, _
pSkipList->len = keyLen;
pSkipList->flags = flags;
pSkipList->keyFn = fn;
pSkipList->seed = rand();
pSkipList->seed = taosRand();
#if 0
// the function getkeycomparfunc is defined in common
......@@ -82,7 +82,7 @@ SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint16_t keyLen, _
}
}
srand((uint32_t)time(NULL));
taosSeedRand((uint32_t)time(NULL));
#if SKIP_LIST_RECORD_PERFORMANCE
pSkipList->state.nTotalMemSize += sizeof(SSkipList);
......@@ -560,9 +560,9 @@ static FORCE_INLINE int32_t getSkipListNodeRandomHeight(SSkipList *pSkipList) {
int32_t n = 1;
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
while ((rand() % factor) == 0 && n <= pSkipList->maxLevel) {
while ((taosRand() % factor) == 0 && n <= pSkipList->maxLevel) {
#else
while ((rand_r(&(pSkipList->seed)) % factor) == 0 && n <= pSkipList->maxLevel) {
while ((taosRandR(&(pSkipList->seed)) % factor) == 0 && n <= pSkipList->maxLevel) {
#endif
n++;
}
......
......@@ -150,7 +150,7 @@ static bool test_variant_int64(int64_t value) {
}
TEST(codingTest, fixed_encode_decode) {
srand(time(0));
taosSeedRand(time(0));
// uint16_t
for (uint16_t value = 0; value <= UINT16_MAX; value++) {
......@@ -204,7 +204,7 @@ TEST(codingTest, fixed_encode_decode) {
}
TEST(codingTest, variant_encode_decode) {
srand(time(0));
taosSeedRand(time(0));
// uint16_t
for (uint16_t value = 0; value <= UINT16_MAX; value++) {
......
......@@ -161,7 +161,7 @@ void recyclePageTest() {
TEST(testCase, resultBufferTest) {
srand(time(NULL));
taosSeedRand(time(NULL));
simpleTest();
writeDownTest();
recyclePageTest();
......
......@@ -47,7 +47,7 @@ void doubleSkipListTest() {
SSkipListKey sk;
for (int32_t i = 0; i < 100; ++i) {
sk.nType = TSDB_DATA_TYPE_DOUBLE;
int32_t idx = abs((i * rand()) % 1000);
int32_t idx = abs((i * taosRand()) % 1000);
sk.dKey = doubleVal[idx];
......@@ -74,7 +74,7 @@ void randKeyTest() {
false, getkey);
int32_t size = 200000;
srand(time(NULL));
taosSeedRand(time(NULL));
printf("generated %d keys is: \n", size);
......@@ -87,7 +87,7 @@ void randKeyTest() {
d->level = level;
int32_t* key = (int32_t*)SL_GET_NODE_KEY(pSkipList, d);
key[0] = rand() % 1000000000;
key[0] = taosRand() % 1000000000;
key[1] = key[0];
......@@ -337,7 +337,7 @@ void duplicatedKeyTest() {
TEST(testCase, skiplist_test) {
assert(sizeof(SSkipListKey) == 8);
srand(time(NULL));
taosSeedRand(time(NULL));
stringKeySkiplistTest();
doubleSkipListTest();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册