diff --git a/native/jni/utils/misc.cpp b/native/jni/utils/misc.cpp index 56b5f8c65..c71768e39 100644 --- a/native/jni/utils/misc.cpp +++ b/native/jni/utils/misc.cpp @@ -35,21 +35,17 @@ int fork_no_orphan() { int gen_rand_str(char *buf, int len, bool varlen) { constexpr char ALPHANUM[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - static mt19937 gen([]{ - mt19937::result_type seed; - if (syscall(__NR_getrandom, &seed, sizeof(seed), 0) < 0) { - // This can happen if device is running a too low Linux version - if (access("/dev/urandom", F_OK) != 0) - mknod("/dev/urandom", 0600 | S_IFCHR, makedev(1, 9)); - int fd = xopen("/dev/urandom", O_RDONLY | O_CLOEXEC); - xxread(fd, &seed, sizeof(seed)); - close(fd); - } + static std::mt19937 gen([]{ + if (access("/dev/urandom", F_OK) != 0) + mknod("/dev/urandom", 0600 | S_IFCHR, makedev(1, 9)); + int fd = xopen("/dev/urandom", O_RDONLY | O_CLOEXEC); + unsigned seed; + xxread(fd, &seed, sizeof(seed)); return seed; }()); - uniform_int_distribution dist(0, sizeof(ALPHANUM) - 2); + std::uniform_int_distribution dist(0, sizeof(ALPHANUM) - 2); if (varlen) { - uniform_int_distribution len_dist(len / 2, len); + std::uniform_int_distribution len_dist(len / 2, len); len = len_dist(gen); } for (int i = 0; i < len - 1; ++i)