aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFeoramund <161657516+Feoramund@users.noreply.github.com>2024-04-15 17:07:05 -0400
committerFeoramund <161657516+Feoramund@users.noreply.github.com>2024-04-15 17:07:05 -0400
commit3e449e93dd60d80c89657d42efa85cb3cc4e8cc3 (patch)
tree6039c7c83dc3e14e6ea5935a08ddd25dedda1fba
parent436c5dc40cda9fdc4203067bc3c52b50bb46332e (diff)
Implement Fisher-Yates shuffle
-rw-r--r--core/math/rand/rand.odin4
1 files changed, 2 insertions, 2 deletions
diff --git a/core/math/rand/rand.odin b/core/math/rand/rand.odin
index 560dc8379..d6a20bd1e 100644
--- a/core/math/rand/rand.odin
+++ b/core/math/rand/rand.odin
@@ -789,8 +789,8 @@ shuffle :: proc(array: $T/[]$E, r: ^Rand = nil) {
return
}
- for i := i64(0); i < n; i += 1 {
- j := int63_max(n, r)
+ for i := i64(n - 1); i > 0; i -= 1 {
+ j := int63_max(i + 1, r)
array[i], array[j] = array[j], array[i]
}
}