57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"crypto/rand"
|
|
"embed"
|
|
"flag"
|
|
"fmt"
|
|
"math/big"
|
|
"strings"
|
|
|
|
"github.com/atotto/clipboard"
|
|
)
|
|
|
|
var (
|
|
//go:embed resources
|
|
res embed.FS
|
|
// embed the resources/nouns.txt & resources/verbs.txt files as arrays of strings split by newlines
|
|
nouns []string
|
|
verbs []string
|
|
)
|
|
|
|
var count int
|
|
var copy bool
|
|
|
|
func init() {
|
|
nounsContents, _ := res.ReadFile("resources/nouns.txt")
|
|
nouns = strings.Split(string(nounsContents), "\n")
|
|
|
|
verbsContents, _ := res.ReadFile("resources/verbs.txt")
|
|
verbs = strings.Split(string(verbsContents), "\n")
|
|
|
|
flag.IntVar(&count, "n", 5, "number of nouns and verbs to print")
|
|
flag.BoolVar(©, "c", false, "copies the output to the clipboard")
|
|
}
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
var output bytes.Buffer
|
|
|
|
for i := 0; i < count; i++ {
|
|
if i > 0 {
|
|
output.WriteString("\n")
|
|
}
|
|
randomNounIdx, _ := rand.Int(rand.Reader, big.NewInt(int64(len((nouns)))))
|
|
randomVerbIdx, _ := rand.Int(rand.Reader, big.NewInt(int64(len((verbs)))))
|
|
var username = fmt.Sprintf("%s-%s", verbs[randomVerbIdx.Int64()], nouns[randomNounIdx.Int64()])
|
|
output.WriteString(username)
|
|
}
|
|
|
|
if copy {
|
|
clipboard.WriteAll(output.String())
|
|
}
|
|
|
|
fmt.Println(output.String())
|
|
}
|