-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (46 loc) · 977 Bytes
/
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 (
"io/ioutil"
"log"
"math/rand"
"os"
"path/filepath"
"time"
)
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
const alphabet = "abcdefghijklmnopqrstuvwxyz"
func main() {
rand.Seed(time.Now().UnixNano())
forAlphabet(func(l1 string) {
forAlphabet(func(l2 string) {
dirP := filepath.Join(l1, l2) // a/a a/b a/c ...
err := os.MkdirAll(dirP, os.ModePerm)
if err != nil {
log.Panic(err)
}
forAlphabet(func(l3 string) {
fileP := filepath.Join(dirP, l3) // a/a/a a/a/b /a/a/c ...
err := ioutil.WriteFile(
fileP,
randomLetters(16), // write out 16 random letters
os.ModePerm,
)
if err != nil {
log.Fatal(err)
}
})
})
})
}
func forAlphabet(f func(letter string)) {
for _, b := range alphabet {
f(string(b))
}
}
func randomLetters(n int) []byte {
b := make([]byte, n)
for i := range b {
b[i] = letterBytes[rand.Intn(len(letterBytes))]
}
return b
}