Cleaned up functions
This commit is contained in:
parent
0fe0cc29a0
commit
de2229ada1
|
@ -17,22 +17,26 @@ func main() {
|
|||
}
|
||||
|
||||
filePath := os.Args[1]
|
||||
randWord := getWord(filePath)
|
||||
|
||||
file, err := os.Open(filePath)
|
||||
fmt.Printf("The chosen name is %v\n", randWord)
|
||||
|
||||
}
|
||||
|
||||
func getWord(path string) (word string) {
|
||||
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
fmt.Println(err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
|
||||
for scanner.Scan() {
|
||||
names = append(names, scanner.Text())
|
||||
}
|
||||
|
||||
fmt.Println(names)
|
||||
//fmt.Println(len(names))
|
||||
|
||||
randName := rand.Intn(len(names) - 0)
|
||||
fmt.Printf("The chosen name is %v\n", names[randName])
|
||||
|
||||
randName := names[rand.Intn(len(names)-0)]
|
||||
return randName
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue