package main import ( "fmt" "math/rand" ) func main() { perm := rand.Perm(5) fmt.Println(perm) }
[2 3 0 4 1]
package main import ( "fmt" "math/rand" ) func main() { perm := rand.Perm(10) fmt.Println(perm) }
[2 9 6 1 8 7 0 4 3 5]In both examples, we use the RandPerm function from the math/rand package to generate a random permutation of integers. The resulting permutation is returned as a slice of integers. We then print the permutation to the console using the fmt package. Therefore, the math/rand package is the package library used for this purpose.