Situation:
I\'ve a slice of values and need to pick up a randomly chosen value from it. Then I want to concatenate it with a fixed string. This is my co
Just pick a random integer mod slice length:
rand.Seed(time.Now().Unix())
reasons := []string{
"Locked out",
"Pipes broke",
"Food poisoning",
"Not feeling well",
}
n := rand.Int() % len(reasons)
fmt.Print("Gonna work from home...", reasons[n])
Playground: http://play.golang.org/p/fEHElLJrEZ. (Note the commend about rand.Seed.)