Programming Language: Golang

Namespace/Package Name: math/rand

Class/Type: Rand

Method/Function: Perm

Examples at hotexamples.com: 27

The math/rand package in Go provides functions for generating random numbers. One of the functions provided by this package is RandPerm, which generates a random permutation of integers from 0 to n-1.

Here are some code examples:

**Example 1:** Generate a random permutation of integers from 0 to 4.

Output:

**Example 2:** Generate a random permutation of integers from 0 to 9.

Output:

Here are some code examples:

package main import ( "fmt" "math/rand" ) func main() { perm := rand.Perm(5) fmt.Println(perm) }

Output:

[2 3 0 4 1]

package main import ( "fmt" "math/rand" ) func main() { perm := rand.Perm(10) fmt.Println(perm) }

Output:

[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.

Frequently Used Methods

Frequently Used Methods

Related

Related in langs