How to generate a random string of a given length in Go?
Hi everyone! I just started learning Go and came across a task: I need to generate random strings of a fixed length, for example, for creating temporary passwords or session identifiers. I tried using the `math/rand` package and simply selecting random characters from a set of letters, but I ran into a problem — the strings are not entirely random, and sometimes they even repeat. Here's my current code:
```go
package main
import (
"fmt"
"math/rand"
)
func main() {
fmt.Println(randString(10))
}
func randString(n int) string {
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
b := make([]rune, n)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
}
return string(b)
}
```
The problem is that