subsonic-tui/internal/common/shuffle.go

17 lines
250 B
Go
Raw Normal View History

package common
import (
"math/rand"
"reflect"
)
func ShuffleSlice(slice interface{}) {
rv := reflect.ValueOf(slice)
swap := reflect.Swapper(slice)
length := rv.Len()
for i := length - 1; i > 0; i-- {
j := rand.Intn(i + 1)
swap(i, j)
}
}