17 lines
250 B
Go
17 lines
250 B
Go
|
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)
|
||
|
}
|
||
|
}
|