pastebin/utils.go

20 lines
336 B
Go
Raw Permalink Normal View History

2017-07-03 06:42:34 +00:00
package main
import (
"crypto/rand"
)
const (
alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
)
// RandomString ...
func RandomString(length int) string {
bytes := make([]byte, length)
rand.Read(bytes)
for i, b := range bytes {
bytes[i] = alphabet[b%byte(len(alphabet))]
}
return string(bytes)
}