Merge pull request #3437 from Feoramund/fisher-yates-shuffle

Implement Fisher-Yates shuffle
This commit is contained in:
Jeroen van Rijn
2024-04-16 10:28:35 +02:00
committed by GitHub
+2 -2
View File
@@ -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]
}
}