golang.org/x/playground@v0.0.0-20230418134305-14ebe15bcd59/examples/sleep.txt (about) 1 // Title: Sleep 2 package main 3 4 import ( 5 "fmt" 6 "math/rand" 7 "time" 8 ) 9 10 func main() { 11 for i := 0; i < 10; i++ { 12 dur := time.Duration(rand.Intn(1000)) * time.Millisecond 13 fmt.Printf("Sleeping for %v\n", dur) 14 // Sleep for a random duration between 0-1000ms 15 time.Sleep(dur) 16 } 17 fmt.Println("Done!") 18 }