go random number
import (
"math/rand"
)
rand.Intn(10)
random number golang
// Uniform Random int (min <= x <= max)
x = rand.Intn(max - min) + min
// Uniform random float (0 <= x <= 1)
x = rand.Float64()
// Uniform random float (min <= x <= max)
x = (rand.Float64() * (max - min)) + min
select a random number between 1 and 5 in golang
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)
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us