
Randomly create a time.Sleep in Golang
To randomly create a time.Sleep in Golang you can use the code snippet below. You may want to simulate a load in your web server and have an arbitrary seconds or minutes before getting the reply. package main import ( "log" "math/rand" "time" ) func main() { rand.Seed(time.Now().UnixNano()) for i := 0; i < 15; i++ { delta := rand.Intn(6 + 1) // randomly generates numbers 1 to 6 time.Sleep(time.Duration(delta) * time....