Clamp RandomPercentage to 0...100
This commit is contained in:
parent
7b306b6147
commit
35952cf7ad
1 changed files with 15 additions and 2 deletions
|
@ -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) \
|
||||
|
|
Loading…
Reference in a new issue