Select A Random Number Between 1 And 5 In Golang

[Solved] Select A Random Number Between 1 And 5 In Golang | Go - Code Explorer | yomemimo.com
Question : select a random number between 1 and 5 in golang

Answered by : black-bird-ll6sntvrza5z

package main
import ( "fmt" "math/rand" "time" #ADDED
)
func main() { // Seed should be set once, better spot is func init() rand.Seed(time.Now().UTC().UnixNano()) #ADDED fmt.Println(randInt(1, 1000))
}
func randInt(min int, max int) int { return min + rand.Intn(max-min)
}

Source : https://stackoverflow.com/questions/44659343/how-to-choose-a-random-number-from-the-range | Last Update : Mon, 29 Jun 20

Answers related to select a random number between 1 and 5 in golang

Code Explorer Popular Question For Go