How to generate random string in Go

How to generate random string in Go

In this post we will give you information about How to generate random string in Go. Hear we will give you detail about How to generate random string in GoAnd how to use it also give you demo for it if it is necessary.

This below example, will show you how to generate a random string of a fixed length in Go.

package mainimport (    "fmt"    "time"    "math/rand")var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")func randSeq(n int) string {    b := make([]rune, n)    for i := range b {        b[i] = letters[rand.Intn(len(letters))]    }    return string(b)}func main() {    rand.Seed(time.Now().UnixNano())    fmt.Println(randSeq(5))}

Output:

DvJaf

Hope this code and post will helped you for implement How to generate random string in Go. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US