github.com/coreservice-io/utils@v0.3.0/rand_util/gen.go (about)

     1  package rand_util
     2  
     3  import (
     4  	"math/rand"
     5  	"time"
     6  )
     7  
     8  func init() {
     9  	ResetSeed()
    10  }
    11  func ResetSeed() {
    12  	rand.Seed(time.Now().UnixNano())
    13  }
    14  
    15  var letterRunes = []rune("abcdefghijklmnopqrstuvwxyz")
    16  
    17  func GenRandStr(n int) string {
    18  	b := make([]rune, n)
    19  	for i := range b {
    20  		b[i] = letterRunes[rand.Intn(len(letterRunes))]
    21  	}
    22  	return string(b)
    23  }