chore: refactored links function e6e49d0e
Steve · 2026-11-16 22:55 1 file(s) · +12 −5
babbler.go +12 −5
79 79
	if n > len(m.words) {
80 80
		n = len(m.words)
81 81
	}
82 +
82 83
	seen := make(map[string]struct{}, n)
83 84
	links := make([]string, 0, n)
84 85
	for len(links) < n {
85 -
		pair := m.words[rand.Intn(len(m.words))] + "/" + m.words[rand.Intn(len(m.words))]
86 -
		if _, dup := seen[pair]; dup {
87 -
			continue
86 +
		link := m.randomLink()
87 +
		if _, dup := seen[link]; dup {
88 +
			continue 
88 89
		}
89 -
		seen[pair] = struct{}{}
90 -
		links = append(links, pair)
90 +
		seen[link] = struct{}{}
91 +
		links = append(links, link)
91 92
	}
92 93
	return links
93 94
}
95 +
96 +
func (m *MarkovChain) randomLink() string {
97 +
	first := m.words[rand.Intn(len(m.words))]
98 +
	second := m.words[rand.Intn(len(m.words))]
99 +
	return first + "/" + second
100 +
}