Optimize random function in ff_compat.c

This commit is contained in:
dingyuan 2022-04-07 13:08:04 +08:00 committed by fengbojiang
parent b963106775
commit c974c5bfbb
1 changed files with 6 additions and 1 deletions

View File

@ -67,6 +67,8 @@ struct prisonlist allprison;
MALLOC_DEFINE(M_FADVISE, "fadvise", "posix_fadvise(2) information"); MALLOC_DEFINE(M_FADVISE, "fadvise", "posix_fadvise(2) information");
int async_io_version; int async_io_version;
extern unsigned int rand_r(unsigned int *seed);
unsigned int seed = 0;
#define M_ZERO 0x0100 /* bzero the allocation */ #define M_ZERO 0x0100 /* bzero the allocation */
@ -294,7 +296,10 @@ arc4rand(void *ptr, unsigned int len, int reseed)
uint32_t uint32_t
arc4random(void) arc4random(void)
{ {
return ff_arc4random(); if (seed == 0) {
seed = ff_arc4random();
}
return (uint32_t)rand_r(&seed);
} }
#if 0 #if 0