Files
lo/docs/data/mutable-shuffle.md
T

751 B
Raw Blame History

name, slug, sourceRef, category, subCategory, playUrl, variantHelpers, similarHelpers, position, signatures
name slug sourceRef category subCategory playUrl variantHelpers similarHelpers position signatures
Shuffle shuffle mutable/slice.go#L57 mutable slice https://go.dev/play/p/2xb3WdLjeSJ
mutable#slice#shuffle
core#slice#shuffle
core#slice#sample
core#slice#samples
20
func Shuffle[T any, Slice ~[]T](collection Slice)

Shuffles the slice in place using the FisherYates algorithm. The operation mutates the original slice order.

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:

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