Go: Generate a random number in a given range

Use the rand.Seed and rand.Intn functions in package math/rand to generate a random number between a and b:

n := a + rand.Intn(b-a+1)

Without the call to rand.Seed, a program will produce the same sequence of pseudo-random numbers for each execution.


Be the first to comment!