-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
54 lines (46 loc) · 2.04 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"fmt"
flag "github.com/spf13/pflag"
"math/rand"
)
var wordsList = []string{
"ipsum", "semper", "habeo", "duo", "ut", "vis", "aliquyam", "eu", "splendide", "Ut", "mei", "eteu", "nec", "antiopam", "corpora", "kasd", "pretium", "cetero", "qui", "arcu", "assentior", "ei", "his", "usu", "invidunt", "kasd", "justo", "ne", "eleifend", "per", "ut", "eam", "graeci", "tincidunt", "impedit", "temporibus", "duo", "et", "facilisis", "insolens", "consequat", "cursus", "partiendo", "ullamcorper", "Vulputate", "facilisi", "donec", "aliquam", "labore", "inimicus", "voluptua", "penatibus", "sea", "vel", "amet", "his", "ius", "audire", "in", "mea", "repudiandae", "nullam", "sed", "assentior", "takimata", "eos", "at", "odio", "consequat", "iusto", "imperdiet", "dicunt", "abhorreant", "adipisci", "officiis", "rhoncus", "leo", "dicta", "vitae", "clita", "elementum", "mauris", "definiebas", "uonsetetur", "te", "inimicus", "nec", "mus", "usu", "duo", "aenean", "corrumpit", "aliquyam", "est", "eum",
}
func getRandomWord() string {
return wordsList[rand.Intn(len(wordsList))]
}
func generateWords(length int) string {
result := "Lorem"
for i := 0; i < length-1; i++ {
result += " " + getRandomWord()
}
return result
}
func generateParagraphs(count, length int, separator string) string {
result := ""
if length == 0 {
for i := 0; i < count; i++ {
result += fmt.Sprintf("%s%s", generateWords(10), separator)
}
return result
} else {
for i := 0; i < count; i++ {
result += fmt.Sprintf("%s%s", generateWords(length), separator)
}
return result
}
}
func main() {
var paragraphs = flag.IntP("paragraphs", "p", 0, "how many paragraphs to generate")
var words = flag.IntP("words", "w", 0, "how many words to generate")
var separator = flag.String("paragraph-separator", "\n\n", "the separator between paragraphs")
flag.Parse()
if *paragraphs == 0 && *words == 0 {
flag.Usage()
} else if *paragraphs != 0 {
fmt.Println(generateParagraphs(*paragraphs, *words, *separator))
} else if *words != 0 {
fmt.Println(generateWords(*words))
}
}