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.

delta := rand.Intn(60 + 1) // randomly generates numbers 1 to 60
time.Sleep(time.Duration(delta) * time.Second) // sleep and wait

Leave a Reply