diff --git a/src/util/src/tutil.c b/src/util/src/tutil.c index 61082b85e39764a148a81f53a45c607f04df3526..644200b0b2115f88e0a1beef3f05a517c6d9edf9 100644 --- a/src/util/src/tutil.c +++ b/src/util/src/tutil.c @@ -40,10 +40,17 @@ int taosRand(void) unsigned long seed; fd = open("/dev/urandom", 0); - if ((fd < 0) || (read(fd, &seed, sizeof(seed)) < 0)) seed = time(0); - if (fd >= 0) close(fd); + if (fd < 0) { + seed = time(0); + } else { + int len = read(fd, &seed, sizeof(seed)); + if (len < 0) { + seed = time(0); + } + srand(seed); + close(fd); + } - srand(seed); return rand(); } #endif