2018-09-03 08:26:07 -04:00
|
|
|
package random
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2020-03-24 09:43:24 -04:00
|
|
|
PossibleNumbers = "0123456789"
|
|
|
|
PossibleLowerCase = "abcdefghijklmnopqrstuvwxyz"
|
|
|
|
PossibleUpperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
|
|
PossibleSpecialCharacter = " !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
|
2018-09-03 08:26:07 -04:00
|
|
|
|
2018-09-05 04:26:52 -04:00
|
|
|
PossibleAlphaNum = PossibleNumbers + PossibleLowerCase + PossibleUpperCase
|
|
|
|
PossibleAlphaNumLower = PossibleNumbers + PossibleLowerCase
|
|
|
|
PossibleAlphaNumUpper = PossibleNumbers + PossibleUpperCase
|
2018-09-03 08:26:07 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
var rnd = rand.New(rand.NewSource(time.Now().UnixNano() + int64(os.Getpid())))
|
|
|
|
|
2018-09-05 04:26:52 -04:00
|
|
|
func Numbers(length int) string { return String(PossibleNumbers, length) }
|
|
|
|
func AlphaNum(length int) string { return String(PossibleAlphaNum, length) }
|
|
|
|
func AlphaNumLower(length int) string { return String(PossibleAlphaNumLower, length) }
|
|
|
|
func AlphaNumUpper(length int) string { return String(PossibleAlphaNumUpper, length) }
|
2018-09-03 08:26:07 -04:00
|
|
|
|
|
|
|
func String(chooseFrom string, length int) (randomString string) {
|
|
|
|
cflen := len(chooseFrom)
|
2018-09-05 04:27:02 -04:00
|
|
|
bytes := make([]byte, length)
|
|
|
|
for i := range bytes {
|
|
|
|
bytes[i] = chooseFrom[rnd.Intn(cflen)]
|
2018-09-03 08:26:07 -04:00
|
|
|
}
|
2018-09-05 04:27:02 -04:00
|
|
|
return string(bytes)
|
2018-09-03 08:26:07 -04:00
|
|
|
}
|