From 39ad1b78eaccb766c91e5e0482a79ac995796558 Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Mon, 15 Jul 2024 13:00:41 -0500 Subject: [PATCH] fix random_range_unsigned_value Previously, it would in some circumstances not generate some values. In particular, dynamic arrays with 0 or 1 element were never tested with an element. Now, all values can always be generated using the specified inclusive range (though the probabilities are not exactly identical). --- templates/test_msg.cpp.em | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/test_msg.cpp.em b/templates/test_msg.cpp.em index aed3970..4490da7 100644 --- a/templates/test_msg.cpp.em +++ b/templates/test_msg.cpp.em @@ -31,10 +31,10 @@ float random_float_val() return -512.0 + static_cast (rand()) /( static_cast (RAND_MAX/(1024.0))); } -// Generate a random unsigned integer value from range +// Generate a random unsigned integer value from range, inclusive uint32_t random_range_unsigned_val(uint32_t min, uint32_t max) { - return min + static_cast (rand()) /( static_cast (RAND_MAX/(max - min))); + return min + static_cast (rand()) % (static_cast (max - min + 1)); }