golang 打乱数组顺序
package main import ( "fmt" "math/rand" "time" ) func MicsSlice(origin []int64, count int) []int64 { tmpOrigin := make([]int64, len(origin)) copy(tmpOrigin, origin) rand.Seed(time.Now().Unix()) rand.Shuffle(len(tmpOrigin), func(i int, j int) { tmpOrigin[i], tmpOrigin[j] = tmpOrigin[j], tmpOrigin[i] }) fmt.Println("result....", tmpOrigin) result := make([]int64, 0, count) for index, value := range tmpOrigin { if index == count { break } result = append(result, value) } return result } func main() { dest := MicsSlice([]int64{1, 2, 3, 4, 5, 6, 73, 2}, 2) fmt.Println("result....", dest) }