aboutsummaryrefslogtreecommitdiff
path: root/stdlib/integers.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-11-03 16:10:03 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-11-03 16:10:03 -0500
commit7ccb7a8a9b8f10d30fd8fca01e849dcad354a855 (patch)
tree1f1bf3c3617f790f80598fa82b8fadafc576e853 /stdlib/integers.c
parent39a58bc129fd9461d54b837bc1650c4c650aa333 (diff)
Use an RNG parameter for array:random(), array:shuffle(),
array:shuffled()
Diffstat (limited to 'stdlib/integers.c')
-rw-r--r--stdlib/integers.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/stdlib/integers.c b/stdlib/integers.c
index f604aa53..8d305daf 100644
--- a/stdlib/integers.c
+++ b/stdlib/integers.c
@@ -440,14 +440,16 @@ public const TypeInfo_t Int$info = {
} \
return bit_array; \
} \
+ public c_type KindOfInt ## $full_random(void) { \
+ c_type r; \
+ arc4random_buf(&r, sizeof(r)); \
+ return r; \
+ } \
public c_type KindOfInt ## $random(c_type min, c_type max) { \
if (min > max) fail("Random minimum value (%ld) is larger than the maximum value (%ld)", min, max); \
if (min == max) return min; \
- if (min == min_val && max == max_val) { \
- c_type r; \
- arc4random_buf(&r, sizeof(r)); \
- return r; \
- } \
+ if (min == min_val && max == max_val) \
+ return KindOfInt ## $full_random(); \
uint64_t range = (uint64_t)max - (uint64_t)min + 1; \
uint64_t min_r = -range % range; \
uint64_t r; \