github.com/interconnectedcloud/qdr-operator@v0.0.0-20210826174505-576d2b33dac7/pkg/utils/random/random.go (about)

     1  package random
     2  
     3  import (
     4  	"math/rand"
     5  	"time"
     6  )
     7  
     8  var initialised = false
     9  var validchars = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
    10  
    11  func GenerateRandomString(n int) string {
    12  	if !initialised {
    13  		rand.Seed(time.Now().UnixNano())
    14  		initialised = true
    15  	}
    16  	b := make([]rune, n)
    17  	for i := range b {
    18  		b[i] = validchars[rand.Intn(len(validchars))]
    19  	}
    20  	return string(b)
    21  }