url_shortener/internal/lib/random/random.go

21 lines
399 B
Go
Raw Permalink Normal View History

2023-12-08 12:59:55 +02:00
package random
import (
"math/rand"
"time"
)
// NewRandomString geneartes random string with given size
func NewRandomString(length int) string {
rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
chars := []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")
b := make([]rune, length)
for i := range b {
b[i] = chars[rnd.Intn(len(chars))]
}
return string(b)
}