mirror of
https://github.com/semaphoreui/semaphore.git
synced 2024-11-23 12:30:41 +01:00
32 lines
377 B
Go
32 lines
377 B
Go
package random
|
|
|
|
import (
|
|
"math/rand"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
r *rand.Rand
|
|
)
|
|
|
|
const (
|
|
chars = "abcdefghijklmnopqrstuvwxyz0123456789"
|
|
)
|
|
|
|
func String(strlen int) string {
|
|
if r == nil {
|
|
r = rand.New(rand.NewSource(
|
|
time.Now().UnixNano(),
|
|
))
|
|
}
|
|
|
|
result := ""
|
|
|
|
for i := 0; i < strlen; i++ {
|
|
index := r.Intn(len(chars))
|
|
result += chars[index : index+1]
|
|
}
|
|
|
|
return result
|
|
}
|