forked from all_user/stat_center
40 lines
715 B
Go
Executable File
40 lines
715 B
Go
Executable File
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
"math/rand"
|
|
)
|
|
|
|
func RandDigits(n uint) string {
|
|
s := ""
|
|
for n != 0 {
|
|
s += fmt.Sprintf("%d", rand.Intn(10))
|
|
n--
|
|
}
|
|
return s
|
|
}
|
|
|
|
const lowerLetter = "abcdefghijklmnopqrstuvwxyz"
|
|
|
|
func RandLowerString(n int) string {
|
|
b := make([]byte, n)
|
|
for i := range b {
|
|
b[i] = lowerLetter[rand.Intn(len(lowerLetter))]
|
|
}
|
|
return string(b)
|
|
}
|
|
|
|
func GetRandomUserName(base string, len int) string {
|
|
return base + RandDigits(2) + RandLowerString(len)
|
|
}
|
|
|
|
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
|
|
|
func RandStringBytes(n int) string {
|
|
b := make([]byte, n)
|
|
for i := range b {
|
|
b[i] = letterBytes[rand.Intn(len(letterBytes))]
|
|
}
|
|
return string(b)
|
|
}
|