Skip to content

Commit 3d2d3c2

Browse files
authored
rand: fix randomness in shuffle() (#25617)
1 parent 3051f77 commit 3d2d3c2

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

vlib/rand/rand.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ pub fn (mut rng PRNG) shuffle[T](mut a []T, config_ config.ShuffleConfigStruct)
460460
// We implement the Fisher-Yates shuffle:
461461
// https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm
462462

463-
for i in config_.start .. new_end - 2 {
463+
for i in config_.start .. new_end - 1 {
464464
x := rng.int_in_range(i, new_end) or { i }
465465
// swap
466466
a_i := a[i]

0 commit comments

Comments
 (0)