crypto/rand is Go’s standard-library package for generating cryptographically secure random values from system-level entropy sources. It costs more than math/rand because it accesses hardware or the operating system, making it appropriate for passwords, tokens, and other security-related objects. section 5.3.3
Choose between Go’s random-number packages according to the consequences of predictable or expensive output:
- Use crypto/rand for passwords, tokens, cryptographic data, and security-related objects. section 5.6
- Use math/rand for small, noncritical applications when lower cost matters more than cryptographic randomness. section 5.3.3
- Use Intn(n) to obtain an integer from zero through n-1, then use it as an index into a corpus. section 5.3.3
Selecting a word for Gordle
A word game can select a random corpus entry by generating an index with Intn(len(corpus)) and returning corpus[index]. The result can then become the game’s solution; tests verify that the returned word belongs to the corpus. section 5.3.3
