kls/links/alphabet.go

31 lines
471 B
Go

package links
import (
"crypto/rand"
"math/big"
)
const codeLength = 5
var (
alphabet = "ABCDEFGHJKMNPQRSTUVWXYZ23456789"
alphabetLength = big.NewInt(int64(len(alphabet)))
)
func randInt() int {
p, err := rand.Int(rand.Reader, alphabetLength)
if err != nil {
panic(err.Error())
}
return int(p.Int64())
}
func GenCode() string {
var code []byte
for i := 0; i < codeLength; i++ {
code = append(code, alphabet[randInt()])
}
return string(code)
}