Advertisement
philnett

Get Random word in Go (Golang)

Jul 1st, 2021
1,003
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.77 KB | None | 0 0
  1. package main // define main project package
  2.  
  3. // import needed packages
  4. import (
  5.     "fmt"
  6.     "math/rand"
  7.     "time"
  8. )
  9.  
  10. // list of words
  11. var words = []string{"aback", "abaft", "abandoned", "abashed", "aberrant", "abhorrent", "abiding", "abject", "ablaze", "able", "abnormal", "innocent", "inquisitive", "insidious", "instinctive", "intelligent", "interesting", "internal", "invincible", "irate", "irritating", "itchy", "jaded", "jagged", "jazzy", "jealous", "jittery", "jobless", "jolly", "joyous", "judicious", "juicy", "jumbled", "jumpy", "juvenile", "kaput", "keen", "kind", "kindhearted", "kindly", "knotty"}
  12.  
  13. func main() {
  14.     rand.Seed(time.Now().Unix())
  15.     word := rand.Intn(len(words))
  16.     selected_word := words[word]
  17.     // Print out the selected word
  18.     fmt.Println(selected_word)
  19. }
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement