Generating random numbers over a range in Go
I found this example at Go Cookbook, which is equivalent to rand.Range(min, max int)
(if that function existed):
rand.Intn(max - min) + min
Don't forget to seed the PRNG before calling any rand
function.
rand.Seed(time.Now().UnixNano())
This will generate random numbers within given range [a, b]
rand.Seed(time.Now().UnixNano())
n := a + rand.Intn(b-a+1)
source