From e783ff4d07ecb0a7bae90651c17735069a094a82 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Thu, 26 Dec 2024 18:36:11 -0700 Subject: libmisc: test_rand: Avoid divide-by-zero, even if its result is ignored --- libmisc/tests/test_rand.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'libmisc/tests/test_rand.c') diff --git a/libmisc/tests/test_rand.c b/libmisc/tests/test_rand.c index 295ea61..282c6a4 100644 --- a/libmisc/tests/test_rand.c +++ b/libmisc/tests/test_rand.c @@ -48,14 +48,14 @@ static void test_n(uint64_t cnt) { bool seen[MAX_SEE_ALL] = {0}; for (int i = 0; i < ROUNDS; i++) { uint64_t val = rand_uint63n(cnt); - sum += ((double)val)/(cnt-1); + sum += val; test_assert(val < cnt); if (cnt < MAX_SEE_ALL) seen[val] = true; } if (cnt > 1) { - test_assert(sum/ROUNDS > 0.45); - test_assert(sum/ROUNDS < 0.55); + test_assert(sum/ROUNDS > 0.45*(cnt-1)); + test_assert(sum/ROUNDS < 0.55*(cnt-1)); } if (cnt < MAX_SEE_ALL) { for (uint64_t i = 0; i < cnt; i++) -- cgit v1.2.3-2-g168b