From: Jens Axboe Date: Tue, 12 Jun 2018 17:37:16 +0000 (-0600) Subject: rand: ensure that rand_between() can reach max value X-Git-Tag: fio-3.8~32 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=c6fc6d2ab2c2fb905ea859f051ad66a54c607916 rand: ensure that rand_between() can reach max value We need to add 1, otherwise the maximum generated value will be end -1. The API is both inclusive. Signed-off-by: Jens Axboe --- diff --git a/lib/rand.h b/lib/rand.h index 4f10fb3c..3554f698 100644 --- a/lib/rand.h +++ b/lib/rand.h @@ -141,9 +141,9 @@ static inline uint64_t rand_between(struct frand_state *state, uint64_t start, uint64_t end) { if (state->use64) - return start + rand64_upto(state, end - start); + return start + rand64_upto(state, 1 + end - start); else - return start + rand32_upto(state, end - start); + return start + rand32_upto(state, 1 + end - start); } extern void init_rand(struct frand_state *, bool);