random number generator golang code example
Example 1: go random number
import (
"math/rand"
)
rand.Intn(10)
Example 2: go rand seed
rand.Seed(time.Now().UTC().UnixNano())
Example 3: 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
Example 4: go generate random number
rand.Intn(max - min) + min