summaryrefslogtreecommitdiff
path: root/libmisc/tests/test_rand.c
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-12-26 18:36:11 -0700
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-12-26 18:36:11 -0700
commite783ff4d07ecb0a7bae90651c17735069a094a82 (patch)
tree4e645373fd7ac701fc2e7e881c6ed97f62f7bb5a /libmisc/tests/test_rand.c
parent10a55a6507a905bafba4b549a926d711c4253007 (diff)
libmisc: test_rand: Avoid divide-by-zero, even if its result is ignored
Diffstat (limited to 'libmisc/tests/test_rand.c')
-rw-r--r--libmisc/tests/test_rand.c6
1 files changed, 3 insertions, 3 deletions
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++)