Generate a random number - Golang
In addition to main
package, we also have lots of built-in packages and one such package is math\rand
.
Each package name is same as last element of the import path. For instance, the "math/rand" package comprises files that begin with the statement package rand. We use Intn(int n)
method(?) which returns a non-negative pseudo-random number in from 0 till n.
package main
import (
"fmt"
"math/rand"
)
func main() {
fmt.Println("My favorite number is", rand.Intn(10))
}