summaryrefslogtreecommitdiffstats
path: root/internal/hole/hole.go
blob: 4824459e1a4dc96111174bd02bc111ee8b5a14ba (plain) (blame)
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
package hole

import (
	"crypto/rand"
	_ "embed"
	"encoding/binary"
	"strings"
)

var (
	//go:embed wordlist.txt
	wordListString string
	wordList       = strings.Split(strings.TrimSuffix(wordListString, "\n"), "\n")
)

func New() string {
	const nWords = 10
	buf := make([]byte, 2*nWords)
	rand.Read(buf)
	words := make([]string, nWords)
	for i := range words {
		words[i] = wordList[binary.NativeEndian.Uint16(buf[2*i:])&0x1fff]
	}
	return strings.Join(words, "-")
}