diff --git a/src/FixedPoints/Utils.h b/src/FixedPoints/Utils.h index 4c07250..3d1ead2 100644 --- a/src/FixedPoints/Utils.h +++ b/src/FixedPoints/Utils.h @@ -203,7 +203,7 @@ template< unsigned Integer, unsigned Fraction > UFixed randomUFixed(const UFixed & inclusiveLowerBound, const UFixed & exclusiveUpperBound) { using InternalType = typename UFixed::InternalType; - return UFixed::fromInternal(inclusiveLowerBound.getInternal() + FIXED_POINTS_DETAILS::RandomHelper::Random() % exclusiveUpperBound.getInternal()); + return UFixed::fromInternal(inclusiveLowerBound.getInternal() + (FIXED_POINTS_DETAILS::RandomHelper::Random() % (exclusiveUpperBound.getInternal() - inclusiveLowerBound.getInternal()))); } // @@ -228,6 +228,7 @@ template< unsigned Integer, unsigned Fraction > SFixed randomSFixed(const SFixed & inclusiveLowerBound, const SFixed & exclusiveUpperBound) { using InternalType = typename SFixed::InternalType; - return SFixed::fromInternal(inclusiveLowerBound.getInternal() + FIXED_POINTS_DETAILS::RandomHelper::Random() % exclusiveUpperBound.getInternal()); + auto value = FIXED_POINTS_DETAILS::RandomHelper::Random(); + return SFixed::fromInternal(inclusiveLowerBound.getInternal() + (abs(value) % (exclusiveUpperBound.getInternal() - inclusiveLowerBound.getInternal()))); } FIXED_POINTS_END_NAMESPACE