mirror of
https://github.com/samber/lo.git
synced 2026-04-22 23:47:11 +08:00
751 B
751 B
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 |
|
|
20 |
|
Shuffles the slice in place using the Fisher–Yates 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