Cleaned up functions

This commit is contained in:
raul 2024-02-08 12:31:01 +00:00
parent 0fe0cc29a0
commit de2229ada1
1 changed files with 12 additions and 8 deletions

View File

@ -17,22 +17,26 @@ func main() {
} }
filePath := os.Args[1] 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 { if err != nil {
fmt.Print(err) fmt.Println(err)
} }
defer file.Close() defer file.Close()
scanner := bufio.NewScanner(file) scanner := bufio.NewScanner(file)
for scanner.Scan() { for scanner.Scan() {
names = append(names, scanner.Text()) names = append(names, scanner.Text())
} }
fmt.Println(names) randName := names[rand.Intn(len(names)-0)]
//fmt.Println(len(names)) return randName
randName := rand.Intn(len(names) - 0)
fmt.Printf("The chosen name is %v\n", names[randName])
} }