Skip to content

Commit

Permalink
Improve rand.shuffle further by splitting into 64-bit and 32-bit parts
Browse files Browse the repository at this point in the history
  • Loading branch information
gingerBill committed Jul 16, 2024
1 parent ba49950 commit 0d881e1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion core/math/rand/rand.odin
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
}

/*
Expand Down

0 comments on commit 0d881e1

Please sign in to comment.