diff options
| author | Feoramund <161657516+Feoramund@users.noreply.github.com> | 2024-04-15 17:07:05 -0400 |
|---|---|---|
| committer | Feoramund <161657516+Feoramund@users.noreply.github.com> | 2024-04-15 17:07:05 -0400 |
| commit | 3e449e93dd60d80c89657d42efa85cb3cc4e8cc3 (patch) | |
| tree | 6039c7c83dc3e14e6ea5935a08ddd25dedda1fba /core/math/rand/rand.odin | |
| parent | 436c5dc40cda9fdc4203067bc3c52b50bb46332e (diff) | |
Implement Fisher-Yates shuffle
Diffstat (limited to 'core/math/rand/rand.odin')
| -rw-r--r-- | core/math/rand/rand.odin | 4 |
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] } } |