Back to Lo

It Shuffle

docs/data/it-shuffle.md

1.53.0424 B
Original Source

Returns a sequence of shuffled values using Fisher-Yates algorithm. Note: this requires collecting all elements in memory.

Examples:

go
seq := func(yield func(int) bool) {
    _ = yield(1)
    _ = yield(2)
    _ = yield(3)
    _ = yield(4)
    _ = yield(5)
}
shuffled := it.Shuffle(seq)
var result []int
for v := range shuffled {
    result = append(result, v)
}
// result contains the same elements in random order