diff options
| author | Andreas Stenmark <astenmark@users.noreply.github.com> | 2025-11-30 21:46:26 +0100 |
|---|---|---|
| committer | Andreas Stenmark <astenmark@users.noreply.github.com> | 2025-11-30 21:46:26 +0100 |
| commit | ad11d3bea03eeb74e43fc518321943db7341e7be (patch) | |
| tree | 73c6cd8f8b59e80f232329be5fdf1bc4b7f09bc7 /core/math | |
| parent | 679d306d0ff0ff9ac451a23ee50d7e44807d5aa6 (diff) | |
Fix #5978: choice_bit_set respects bit_set domain
Diffstat (limited to 'core/math')
| -rw-r--r-- | core/math/rand/rand.odin | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/core/math/rand/rand.odin b/core/math/rand/rand.odin index 4ffcc595e..41b066255 100644 --- a/core/math/rand/rand.odin +++ b/core/math/rand/rand.odin @@ -1199,11 +1199,14 @@ choice_bit_set :: proc(set: $T/bit_set[$E], gen := context.random_generator) -> return {}, false } - core_set := transmute(intrinsics.type_bit_set_underlying_type(T))set + target := int_max(total_set, gen) - for target := int_max(total_set, gen); target > 0; target -= 1 { - core_set &= core_set - 1 + for value in set { + if target == 0 { + return value, true + } + target -= 1 } - return E(intrinsics.count_trailing_zeros(core_set)), true + return {}, false } |