A pseudo-random number generator produces values that behave randomly for ordinary program tasks while using an algorithm and an underlying source. Go's math/rand package is suitable for small, noncritical applications; crypto/rand uses system-level entropy and costs more, making it appropriate for passwords, tokens, and security-related objects. section 5.3.3
Use the generator by choosing a bounded index:
- Call rand.Intn(n) to obtain a value from 0 inclusive through n exclusive. section 5.3.3
- Use the value to select an element, such as a word, from a corpus. section 5.3.3
- Understand seeding differences: Go versions before 1.20 required rand.Seed, while newer programs seed the generator at startup. section 5.3.3
Selecting a random word
func pickWord(corpus []string) string { index := rand.Intn(len(corpus)) return corpus[index] } A focused test checks that the result belongs to the corpus rather than expecting one particular word.









