From c974c5bfbb5a2ac902e9b608bf1f08de6c699eb9 Mon Sep 17 00:00:00 2001 From: dingyuan Date: Thu, 7 Apr 2022 13:08:04 +0800 Subject: [PATCH] Optimize random function in ff_compat.c --- lib/ff_compat.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/ff_compat.c b/lib/ff_compat.c index 6ef6720a6..2e3810845 100644 --- a/lib/ff_compat.c +++ b/lib/ff_compat.c @@ -67,6 +67,8 @@ struct prisonlist allprison; MALLOC_DEFINE(M_FADVISE, "fadvise", "posix_fadvise(2) information"); int async_io_version; +extern unsigned int rand_r(unsigned int *seed); +unsigned int seed = 0; #define M_ZERO 0x0100 /* bzero the allocation */ @@ -294,7 +296,10 @@ arc4rand(void *ptr, unsigned int len, int reseed) uint32_t arc4random(void) { - return ff_arc4random(); + if (seed == 0) { + seed = ff_arc4random(); + } + return (uint32_t)rand_r(&seed); } #if 0