From c6fc6d2ab2c2fb905ea859f051ad66a54c607916 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Tue, 12 Jun 2018 11:37:16 -0600 Subject: [PATCH] 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 --- lib/rand.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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); -- 2.25.1