github.com/argoproj/argo-events@v1.9.1/common/string.go (about)

     1  package common
     2  
     3  import (
     4  	"crypto/rand"
     5  	"math/big"
     6  )
     7  
     8  // generate a random string with given length
     9  func RandomString(length int) string {
    10  	seeds := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
    11  	result := make([]byte, length)
    12  	for i := 0; i < length; i++ {
    13  		num, _ := rand.Int(rand.Reader, big.NewInt(int64(len(seeds))))
    14  		result[i] = seeds[num.Int64()]
    15  	}
    16  	return string(result)
    17  }