Last active
August 29, 2015 14:23
-
-
Save pauladam/f41bb2320b5fdd9180fb to your computer and use it in GitHub Desktop.
Scribe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // tree | |
| // . | |
| // ├── bin | |
| // │ └── scribe | |
| // └── src | |
| // └── scribe | |
| // └── scribe.go | |
| // $ gb build all; bin/scribe | |
| // Jesse | |
| package main | |
| import "os" | |
| import "fmt" | |
| import "time" | |
| import "bufio" | |
| import "math/rand" | |
| func main() { | |
| var names []string | |
| inFile, _ := os.Open("names") | |
| defer inFile.Close() | |
| scanner := bufio.NewScanner(inFile) | |
| scanner.Split(bufio.ScanLines) | |
| for scanner.Scan() { names = append(names, scanner.Text()) } | |
| rand.Seed(time.Now().UTC().UnixNano()) | |
| fmt.Println(names[rand.Intn(len(names))]) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
to be idiomatic (but kinda silly for this use case) you might want to check the err return from
os.Open()and maybepanic. Also, newline inside aforblock 😃