Clamp RandomPercentage to 0...100

This commit is contained in:
Martin Griffin 2023-04-05 13:07:02 +01:00
parent 7b306b6147
commit 35952cf7ad

View File

@ -80,8 +80,21 @@ enum RandomTag
#define RandomPercentage(tag, t) \
({ \
const u8 weights[] = { 100 - t, t }; \
RandomWeightedArray(tag, 100, ARRAY_COUNT(weights), weights); \
u32 r; \
if (t <= 0) \
{ \
r = FALSE; \
} \
else if (t >= 100) \
{ \
r = TRUE; \
} \
else \
{ \
const u8 weights[] = { 100 - t, t }; \
r = RandomWeightedArray(tag, 100, ARRAY_COUNT(weights), weights); \
} \
r; \
})
#define RandomElement(tag, array) \