package main
import (
"crypto/rand"
"fmt"
"math/big"
)
func shuffle(array []int) {
for i := len(array) - 1; i >= 0; i-- {
result, err := rand.Int(rand.Reader, big.NewInt(int64(i+1)))
if err != nil {
panic(err)
}
j := int(result.Int64())
array[i], array[j] = array[j], array[i]
}
}
func main() {
a := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
fmt.Println(a)
shuffle(a)
fmt.Println(a)
}
[1 2 3 4 5 6 7 8 9 10]
[7 2 1 10 3 8 9 6 5 4]
[1 2 3 4 5 6 7 8 9 10]
[9 2 1 5 3 10 7 4 6 8]
[1 2 3 4 5 6 7 8 9 10]
[8 1 6 7 2 3 10 9 4 5]