aboutsummaryrefslogtreecommitdiff
path: root/core/math
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2024-07-16 18:36:31 +0100
committergingerBill <bill@gingerbill.org>2024-07-16 18:36:31 +0100
commit0d881e1561d62065a6c702c3eabadc253a8f2bc6 (patch)
treed7a1e2fb203304f832bb7d7876265832418fe008 /core/math
parentba4995045465204805d55318efa0cbf086e4265d (diff)
Improve rand.shuffle further by splitting into 64-bit and 32-bit parts
Diffstat (limited to 'core/math')
-rw-r--r--core/math/rand/rand.odin8
1 files changed, 7 insertions, 1 deletions
diff --git a/core/math/rand/rand.odin b/core/math/rand/rand.odin
index 4f736985f..e02f3db80 100644
--- a/core/math/rand/rand.odin
+++ b/core/math/rand/rand.odin
@@ -618,10 +618,16 @@ shuffle :: proc(array: $T/[]$E, gen := context.random_generator) {
return
}
- for i := i64(n - 2); i >= 0; i -= 1 {
+ i := n - 1
+ for ; i > (1<<31 - 2); i -= 1 {
j := int63_max(i + 1, gen)
array[i], array[j] = array[j], array[i]
}
+
+ for ; i > 0; i -= 1 {
+ j := int31_max(i32(i + 1), gen)
+ array[i], array[j] = array[j], array[i]
+ }
}
/*