Shuffle List in Go
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
rand.Seed(time.Now().UnixNano())
a := []int{1, 2, 3, 4, 5}
for i := len(a) - 1; i > 0; i-- {
j := rand.Intn(i + 1)
a[i], a[j] = a[j], a[i]
}
fmt.Println(a)
// You can also use rand.Shuffle
b := []int{6, 7, 8, 9, 10}
rand.Shuffle(len(b), func(i, j int) {
b[i], b[j] = b[j], b[i]
})
fmt.Println(b)
}