From: Miroslav Lichvar Date: Thu, 23 Sep 2021 07:34:47 +0000 (+0200) Subject: test: fix incorrect use of RAND_MAX X-Git-Tag: 4.2-pre1~50 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9600993c282d15353987f35b2b0f7475b37da5c4;p=thirdparty%2Fchrony.git 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. --- diff --git a/test/unit/test.c b/test/unit/test.c index 0f5638d8..94619c13 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