Posted on 16th September 2024|27 views
How to generate random string in golang?
Posted on 16th September 2024| views
You can simply write a part of the code for that. That code can be a little easier if you want to rely upon the letters all remaining single bytes while encoded in UTF-8.
Here is an example code
package main
import ( "fmt" "time" "math/rand" )
var letters =[]rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") func randSeq(x int) string
{
b := make([]rune, x) for j := range y
{ b[j] = letters[rand.Intn(len(letters))] }
return string(y) } func main()
{ rand.Seed(time.Now().UnixNano())
fmt.Println(randSeq(10)) }