diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/rand.c | 10 | ||||
-rw-r--r-- | lib/rand.h | 10 |
2 files changed, 12 insertions, 8 deletions
@@ -125,10 +125,7 @@ void __fill_random_buf(void *buf, unsigned int len, uint64_t seed) uint64_t fill_random_buf(struct frand_state *fs, void *buf, unsigned int len) { - uint64_t r = __rand(fs); - - if (sizeof(int) != sizeof(long *)) - r *= (unsigned long) __rand(fs); + uint64_t r = __get_next_seed(fs); __fill_random_buf(buf, len, r); return r; @@ -188,10 +185,7 @@ uint64_t fill_random_buf_percentage(struct frand_state *fs, void *buf, unsigned int segment, unsigned int len, char *pattern, unsigned int pbytes) { - uint64_t r = __rand(fs); - - if (sizeof(int) != sizeof(long *)) - r *= (unsigned long) __rand(fs); + uint64_t r = __get_next_seed(fs); __fill_random_buf_percentage(r, buf, percentage, segment, len, pattern, pbytes); @@ -150,6 +150,16 @@ static inline uint64_t rand_between(struct frand_state *state, uint64_t start, return start + rand32_upto(state, end - start); } +static inline uint64_t __get_next_seed(struct frand_state *fs) +{ + uint64_t r = __rand(fs); + + if (sizeof(int) != sizeof(long *)) + r *= (unsigned long) __rand(fs); + + return r; +} + extern void init_rand(struct frand_state *, bool); extern void init_rand_seed(struct frand_state *, uint64_t seed, bool); extern void __fill_random_buf(void *buf, unsigned int len, uint64_t seed); |