lundi 30 novembre 2015

Pick a random value from a Go Slice

So in my quest to learn new languages,I have decided to learn Go and this is the very first day so please be gentle on me..I have a slice of values and i need to randomly pickup a value and then concatenate it with a fixed string..This is what i have till now..

func main() {
//create the reasons slice and append reasons to it
reasons := make([]string, 0)
reasons = append(reasons,
    "Locked out",
    "Pipes broke",
    "Food poisoning",
    "Not feeling well")

message := fmt.Sprint("Gonna work from home...", pick a random reason )
}

Is there an inbuilt function which can help me do that "pick a random reason" part..?




Aucun commentaire:

Enregistrer un commentaire