Programming Language: Golang

Namespace/Package Name: math/rand

Class/Type: Rand

Method/Function: Intn

Examples at hotexamples.com: 30

The `math/rand` package in Go provides a random number generator. One of the most commonly used functions in this package is `RandIntn`, which generates a random integer in the range [0,n).

Example:

Example:

package main import ( "fmt" "math/rand" "time" ) func main() { rand.Seed(time.Now().UnixNano()) // Set a new seed based on the current time fmt.Println("Random number between 0 and 4:", rand.Intn(5)) // Generate a random integer between 0 and 4 fmt.Println("Random number between 0 and 99:", rand.Intn(100)) // Generate a random integer between 0 and 99 }In this example, we first set a new seed for the random number generator based on the current time. Then we use `rand.Intn` to generate a random integer between 0 and 4, and between 0 and 99 respectively. The package library `math/rand`.

Frequently Used Methods

Frequently Used Methods

Related

Related in langs