Back to Lo

Mutable Shuffle

docs/data/mutable-shuffle.md

1.53.0391 B
Original Source

Shuffles the slice in place using the Fisher–Yates algorithm. The operation mutates the original slice order.

go
import lom "github.com/samber/lo/mutable"

list := []int{0, 1, 2, 3, 4, 5}
lom.Shuffle(list)
// list order is randomized, e.g., []int{1, 4, 0, 3, 5, 2}

With strings:

go
names := []string{"alice", "bob", "carol"}
lom.Shuffle(names)
// names order is randomized