From 9600993c282d15353987f35b2b0f7475b37da5c4 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Thu, 23 Sep 2021 09:34:47 +0200 Subject: [PATCH] test: fix incorrect use of RAND_MAX On some systems (e.g. Solaris/OpenIndiana) rand() and random() have different ranges. RAND_MAX is the maximum value returned by rand(), but random() should always have a range of 0 through 2^31-1. This fixes multiple failures in different tests. --- test/unit/test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/test.c b/test/unit/test.c index 0f5638d..94619c1 100644 --- a/test/unit/test.c +++ b/test/unit/test.c @@ -90,7 +90,7 @@ main(int argc, char **argv) double TST_GetRandomDouble(double min, double max) { - return min + (double)random() / RAND_MAX * (max - min); + return min + random() / 2147483647.0 * (max - min); } void